【发布时间】:2015-11-06 15:20:27
【问题描述】:
那里有一个错误。我试图在循环中写一个继续,但这没有用(或跳回)。我是初学者所以请在读完这篇文章后不要生气。请帮帮我!
somepoint: { Random first = new Random();
int b = first.nextInt(8);
if (b==0)
{
x=x+20;
for (int c=0; c<100; c++)
{
if (x>=950)
{
JOptionPane.showMessageDialog(null, "Winner is white car!");
return;
}
else
{
continue somepoint; //cannot be used outside, help
}
}
}
else if (b==1)
{
x2=x2+20;
for (int c=0; c<100; c++)
{
if (x2>=950)
{
JOptionPane.showMessageDialog(null, "Winner is red car!");
return;
}
else
{
continue somepoint; //cannot be used outside,
}
}
}
else if (b==2) ...
【问题讨论】:
-
人们通常认为像这样跳入代码是不好的做法。您是否尝试过使用其他循环结构(例如 while 循环)来包含代码?
-
@phflack noo,好的,我试试这个
标签: java if-statement for-loop continue