-1
那裏有一個錯誤。我試圖寫一個繼續循環,這不起作用(或跳回)。我是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) ...
人們通常認爲這是不好的做法跳到這樣的代碼。您是否嘗試過使用其他循環結構(如while循環)來包含代碼? – phflack
@phflack noo,okey我會試試這個 –