break 与 continnue 的困惑

 

import javax.swing.JOptionPane;
import java.util.*;

public class Figureguess_extension
{
 public static void main(String args[])
 {
  int x;
  int spread;
  int userscore=100;
  int systemscore=100;
  String s;
  Random rand=new Random();
  for(int i=1;;i++)
  {
   s=JOptionPane.showInputDialog("Enter an positive integer less than 100");
   x=Integer.parseInt(s);
   spread=Math.abs(x-rand.nextInt(100));
   switch(spread)
   {
   case 0:
    userscore+=10;
    systemscore-=10;
    JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
    continue;
   case 1:
   case 2:
   case 3:
   case 4:
   case 5:
    userscore+=5;
       systemscore-=5;
       JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
       continue;
   case 6:
   case 7:
   case 8:
   case 9:
   case 10:
    userscore+=0;
       systemscore-=0;
       JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
       continue;
   case 11:
   case 12:
   case 13:
   case 14:
   case 15:
   case 16:
   case 17:
   case 18:
   case 19:
   case 20:
    userscore-=5;
       systemscore+=5;
       JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
       continue;
     default:
      userscore-=10;
         systemscore+=10;
         JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
         continue;
        
    
    
    
         
   }
  }
 }
}

书上说break与continue不同,但是switch也是循环么?如果是循环,那么上面的程序continue就应该改为break!难怪不孚吾望!

以前一直以为只有for是循环!尴尬

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值