// control/LabeledFor.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.// For loops with "labeled break"/"labeled continue."public class LabeledFor {public static void main(String[] args) {int i = 0;outer: // Can't have statements herefor(; true ;) { // infinite loopinner: // Can't have statements herefor(; i < 10; i++) {System.out.println("i = " + i);if(i == 2) {System.out.println("continue");continue;}if(i == 3) {System.out.println("break");i++; // Otherwise i never// gets incremented.break;}if(i == 7) {System.out.println("continue outer");i++; // Otherwise i never// gets incremented.continue outer;}if(i == 8) {System.out.println("break outer");break outer;}for(int k = 0; k < 5; k++) {if(k == 3) {System.out.println("continue inner");continue inner;}}}}// Can't break or continue to labels here}}/* Output:i = 0continue inneri = 1continue inneri = 2continuei = 3breaki = 4continue inneri = 5continue inneri = 6continue inneri = 7continue outeri = 8break outer*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。