Thinking in JAVA label for ,similar to go to.
2010-08-26 15:43
351 查看
public class LabeledFor { public static void main(String[] args) { int i = 0; outer: // Can’t have statements here for (; i<10;i++) { // infinite loop inner: // Can’t have statements here for (; i < 10; i++) { out.print("i = " + i); if (i == 2) { out.println("continue"); continue; } if (i == 3) { out.println("break"); i++; // Otherwise i never // gets incremented. break; } if (i == 7) { out.println("continue outer"); i++; // Otherwise i never // gets incremented. continue outer; } if (i == 8) { out.println("break outer"); break outer; } for (int k = 0; k < 5; k++) { if (k == 3) { out.println("continue inner"); continue inner; } } } } // Can’t break or continue to labels here } }
Note that break breaks out of the for loop, and that the increment expression doesn’t occur until the end of the pass through the for loop. Since break skips the increment expression, the increment is performed directly in the case of i == 3. The continue outer statement in the case of i == 7 also goes to the top of the loop and also skips the increment, so it too is incremented directly.
continue outer .相当于在最外面那个循环里面调用continue.里面的i值还是要增加的。
continue inner;相当于在里面那个循环里面调用continue;里面的i值也是要增加的。
相关文章推荐
- NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java class
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicab
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicable(四十四)
- HADOOP:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable终于解决了
- unable to load native-hadoop library for your platform using builtin-java classes
- WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- Web Tier to Go With Java EE 5: Summary of New Features in JavaServer Faces 1.2 Technology
- How to tacktrace In Android for Java code
- How to implement the similar mechanism with Java final in c++?
- Web Tier to Go With Java EE 5: Summary of New Features in Java Standard Tag Library (JSTL) 1.2
- hadoop错误INFO util.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- Unable to find a value for "字段名" in object of class java.lang.String using operator "."
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicabl
- Web Tier to Go With Java EE 5: Summary of New Features in JSP 2.1 Technology
- 使用hadoop命令警告提示:Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
- Unable to find a value for "dwmc" in object of class "java.lang.String" using operator "." (null
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicabl
- Hadoop出现错误:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable,解决方案
- 《Thinking in java》第四版中的例子tupeinfo/SweetShop.java存在问题,全限定名;forName()方法
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicable