使用标签并在if-else语句中插入 [英] Using label and break in if-else statement
本文介绍了使用标签并在if-else语句中插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码,可以在特定条件下(当x和y都等于零时)从数组生成随机数。我希望控件跳转到标签。但是控件在任何情况下都不会跳转到标签。我想知道我是否做对了?
I have this code which generates random number from an array, at a particular condition (when x and y both are equal to zero). I want the control to jump to the label. But the control never jumps to the label in any condition. I wanted to know that whether I am doing it right or not?
int[] arr = {0, 1, 2};
Random rn = new Random();
label: {
//some code
if (x != 0 && y !=0) {
//some code
} else {
break label;
}
}
推荐答案
尝试避免使用标签。您在那里可以做的是:
Try to Avoid using labels. What you could do there, is:
while(true) {
if(x == 0 && y == 0) {
break;
}
// some stuff with x and y
}
这篇关于使用标签并在if-else语句中插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文