标签:字符串 bsp 增量 sys 结构 byte case pre for
if(boolean)
switch(byte short int char enum 字符串)
1 switch(str) {//打印出3 2 case "春天" : System.out.println(1);break; 3 case "夏天" : System.out.println(2);break; 4 case "秋天" : System.out.println(3);break; 5 case "冬天" : System.out.println(4);break; 6 default : break; 7 }
1 System.out.println("循环测试开始\n\n"); 2 3 outer: 4 for(int i = 0;i < 6; ++i) { 5 for(int j = 0;j < 4; ++j) { 6 System.out.println("i = " + i + "j = " + j); 7 if(j == 2) 8 break outer; 9 } 10 } 11 打印结果: 12 循环测试开始 13 14 15 i = 0j = 0 16 i = 0j = 1 17 i = 0j = 2
1 System.out.println("循环测试开始\n\n"); 2 3 outer: 4 for(int i = 0;i < 5; ++i) { 5 for(int j = 0;j < 3; ++j) { 6 if(j == 1) 7 continue outer; 8 System.out.println("i = " + i + " j = " + j); 9 } 10 }
打印结果:
循环测试开始 i = 0 j = 0 i = 1 j = 0 i = 2 j = 0 i = 3 j = 0 i = 4 j = 0
1 System.out.println("测试for开始\n\n"); 2 3 for(int i = 0;i < 4; ++i) { 4 if(i == 2) 5 continue; 6 System.out.println("i = " + i); 7 } 8 System.out.println("测试while开始\n\n"); 9 int k = 0; 10 while(k < 4) { 11 if(k == 2) 12 continue; 13 System.out.println("k = " + k); 14 ++k;//continue后,++k永远没机会执行了,循环一直执行,没死!只是无法打印k了,就像阻塞了 15 }
for的循环增量会执行,但是while的循环增量不会执行!!!
打印结果:
测试for开始 i = 0 i = 1 i = 3 测试while开始 k = 0 k = 1 //程序卡死中...
标签:字符串 bsp 增量 sys 结构 byte case pre for
原文地址:http://www.cnblogs.com/joyeehe/p/7881622.html