Java 循环使用“;“继续”;还是恢复原状

Java 循环使用“;“继续”;还是恢复原状,java,if-statement,for-loop,continue,Java,If Statement,For Loop,Continue,A那里有个错误。我试图写一个continue-in循环,但没有成功(或者跳到后面)。我是begginer soo,请不要在读了这篇文章后生气。请帮帮我 somepoint: { Random first = new Random(); int b = first.nextInt(8); if (b==0) { x=x+20; for (int c=0; c<100; c++)

A那里有个错误。我试图写一个continue-in循环,但没有成功(或者跳到后面)。我是begginer soo,请不要在读了这篇文章后生气。请帮帮我

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) ...
somepoint:{Random first=new Random();
int b=第一个。下一个(8);
如果(b==0)
{
x=x+20;
对于(int c=0;c=950)
{
showMessageDialog(空,“获胜者是白色汽车!”);
返回;
}
其他的
{
continue somepoint;//不能在外部使用,请帮助
}
}
}
else如果(b==1)
{
x2=x2+20;
对于(int c=0;c=950)
{
showMessageDialog(空,“获胜者是红色汽车!”);
返回;
}
其他的
{
continue somepoint;//不能在外部使用,
}
}
}
如果(b==2)。。。

像这样跳入代码是一种非常糟糕的做法。你是否考虑过使用递归方法?< /P>

如果你想正确地使用<代码>继续< /代码>,你应该读这个。

人们通常认为这样的代码是不好的做法。您是否尝试过使用其他循环结构(如while循环)来包含代码?@phflack noo,好的,我试试这个