5. break&continue
package com.kuangshen.struct; public class BreakDemo01 { public static void main(String[] args) { int i = 0; while (i<100){ i++; System.out.println(i); if (i==30){ break; } } } }
-
continue语句用在循环语句体中,用于终止某次循环过程,即跳过循环中尚未执行的语句,接着执行下一次是否执行循环的判定
package com.kuangshen.struct; public class ContinueDemo01 { public static void main(String[] args) { int i = 0; while (i<100){ i++; if (i%10==0){ System.out.println(); continue; } System.out.print(i+" "); } } }
-
标签
package com.kuangshen.struct; public class LbaleDemo01 { public static void main(String[] args) { //打印101——150之间的所有质数 int count = 0; outer:for (int i=101;i<=150;i++){ for (int j=2;j<=i/2;j++){ if (i%j==0){ continue outer; } }System.out.println(i); } } }