GoTo Next Iteration in For Loop in java

后端 未结 6 1585
悲&欢浪女
悲&欢浪女 2020-12-22 23:24

Is there a token in java that skips the rest of the for loop? Something like VB\'s Continue in java.

6条回答
  •  情深已故
    2020-12-22 23:57

    As mentioned in all other answers, the keyword continue will skip to the end of the current iteration.

    Additionally you can label your loop starts and then use continue [labelname]; or break [labelname]; to control what's going on in nested loops:

    loop1: for (int i = 1; i < 10; i++) {
        loop2: for (int j = 1; j < 10; j++) {
            if (i + j == 10)
                continue loop1;
    
            System.out.print(j);
        }
        System.out.println();
    }
    

提交回复
热议问题