标签:操作 public nbsp code others 开始 第一个 break 使用
break可用于循环和switch...case...语句中。
执行完满足case条件的内容内后结束switch,不执行下面的语句。
eg:
public static void breakSwitch1() { int n = 1; switch (n) { case 1: System.out.println("this is one."); break; case 2: System.out.println("this is two."); break; default: System.out.println("Others."); } }
结果:
this is one.
eg2:
public static void breakSwitch2() { int n = 1; switch (n) { case 1: System.out.println("this is one."); //break; case 2: System.out.println("this is two."); break; default: System.out.println("Others."); } }
结果:
this is one.
this is two.
如果不使用break语句则所有的操作将在第一个满足条件之后的语句全部输出,直到遇到break语句为止;
当循环语句执行到continue时,当次循环结束,重新开始下一轮循环。如果已经是最后一轮循环了,那么这是的continue就与break效果一样了。
Java 中 break和 continue 的使用方法及区别
标签:操作 public nbsp code others 开始 第一个 break 使用
原文地址:http://www.cnblogs.com/liushuncheng/p/6517426.html