用“继续”或回到条件循环

问题描述:

那里有一个错误。我试图写一个继续循环,这不起作用(或跳回)。我是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) ... 
+0

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

+0

@phflack noo,okey我会试试这个 –

跳这样的代码是一个非常糟糕的做法。你有没有考虑使用递归方法?

如果你想正确使用continue,你应该阅读这个question