logo

Java Continue 문

continue 문은 루프의 다음 반복으로 즉시 점프해야 할 때 루프 제어 구조에서 사용됩니다. for 루프나 while 루프와 함께 사용할 수 있습니다.

자바 계속 진술 루프를 계속하는 데 사용됩니다. 프로그램의 현재 흐름을 계속하고 지정된 조건에서 나머지 코드를 건너뜁니다. 내부 루프의 경우 내부 루프만 계속됩니다.

for 루프, while 루프, do-while 루프와 같은 모든 유형의 루프에서 Java continue 문을 사용할 수 있습니다.

통사론:

 jump-statement; continue; 

Java Continue 문 예

계속Example.java

 //Java Program to demonstrate the use of continue statement //inside the for loop. public class ContinueExample { public static void main(String[] args) { //for loop for(int i=1;i<=10;i++){ if(i="=5){" using continue statement continue; it will skip the rest } system.out.println(i); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <p>As you can see in the above output, 5 is not printed on the console. It is because the loop is continued when it reaches to 5.</p> <h2>Java Continue Statement with Inner Loop</h2> <p>It continues inner loop only if you use the continue statement inside the inner loop.</p> <p> <strong>ContinueExample2.java</strong> </p> <pre> //Java Program to illustrate the use of continue statement //inside an inner loop public class ContinueExample2 { public static void main(String[] args) { //outer loop for(int i=1;i<=3;i++){ inner loop for(int j="1;j&lt;=3;j++){" if(i="=2&amp;&amp;j==2){" using continue statement inside continue; } system.out.println(i+' '+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 </pre> <h2>Java Continue Statement with Labelled For Loop</h2> <p>We can use continue statement with a label. This feature is introduced since JDK 1.5. So, we can continue any loop in Java now whether it is outer loop or inner.</p> <p> <strong>Example:</strong> </p> <p> <strong>ContinueExample3.java</strong> </p> <pre> //Java Program to illustrate the use of continue statement //with label inside an inner loop to continue outer loop public class ContinueExample3 { public static void main(String[] args) { aa: for(int i=1;i<=3;i++){ bb: for(int j="1;j&lt;=3;j++){" if(i="=2&amp;&amp;j==2){" using continue statement with label aa; } system.out.println(i+' '+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 3 1 3 2 3 3 </pre> <h2>Java Continue Statement in while loop</h2> <p> <strong>ContinueWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the while loop. public class ContinueWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using continue statement i++; continue; it will skip the rest } system.out.println(i); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <h2>Java Continue Statement in do-while Loop</h2> <p> <strong>ContinueDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the Java do-while loop. public class ContinueDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using continue statement i++; continue;//it will skip the rest statement } System.out.println(i); i++; }while(i<=10); } < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <hr></=10);></pre></=10){></pre></=3;i++){></pre></=3;i++){></pre></=10;i++){>

위 출력에서 ​​볼 수 있듯이 콘솔에 5가 인쇄되지 않습니다. 5에 도달하면 루프가 계속되기 때문이다.

내부 루프가 있는 Java Continue 문

내부 루프 내에서 continue 문을 사용하는 경우에만 내부 루프를 계속합니다.

계속Example2.java

 //Java Program to illustrate the use of continue statement //inside an inner loop public class ContinueExample2 { public static void main(String[] args) { //outer loop for(int i=1;i<=3;i++){ inner loop for(int j="1;j&lt;=3;j++){" if(i="=2&amp;&amp;j==2){" using continue statement inside continue; } system.out.println(i+\' \'+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 </pre> <h2>Java Continue Statement with Labelled For Loop</h2> <p>We can use continue statement with a label. This feature is introduced since JDK 1.5. So, we can continue any loop in Java now whether it is outer loop or inner.</p> <p> <strong>Example:</strong> </p> <p> <strong>ContinueExample3.java</strong> </p> <pre> //Java Program to illustrate the use of continue statement //with label inside an inner loop to continue outer loop public class ContinueExample3 { public static void main(String[] args) { aa: for(int i=1;i<=3;i++){ bb: for(int j="1;j&lt;=3;j++){" if(i="=2&amp;&amp;j==2){" using continue statement with label aa; } system.out.println(i+\' \'+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 3 1 3 2 3 3 </pre> <h2>Java Continue Statement in while loop</h2> <p> <strong>ContinueWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the while loop. public class ContinueWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using continue statement i++; continue; it will skip the rest } system.out.println(i); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <h2>Java Continue Statement in do-while Loop</h2> <p> <strong>ContinueDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the Java do-while loop. public class ContinueDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using continue statement i++; continue;//it will skip the rest statement } System.out.println(i); i++; }while(i<=10); } < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <hr></=10);></pre></=10){></pre></=3;i++){></pre></=3;i++){>

For 루프라는 레이블이 있는 Java Continue 문

레이블과 함께 continue 문을 사용할 수 있습니다. 이 기능은 JDK 1.5부터 도입되었습니다. 따라서 이제 외부 루프이든 내부 루프이든 Java에서 모든 루프를 계속할 수 있습니다.

예:

knn 알고리즘

계속Example3.java

 //Java Program to illustrate the use of continue statement //with label inside an inner loop to continue outer loop public class ContinueExample3 { public static void main(String[] args) { aa: for(int i=1;i<=3;i++){ bb: for(int j="1;j&lt;=3;j++){" if(i="=2&amp;&amp;j==2){" using continue statement with label aa; } system.out.println(i+\' \'+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 3 1 3 2 3 3 </pre> <h2>Java Continue Statement in while loop</h2> <p> <strong>ContinueWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the while loop. public class ContinueWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using continue statement i++; continue; it will skip the rest } system.out.println(i); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <h2>Java Continue Statement in do-while Loop</h2> <p> <strong>ContinueDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the Java do-while loop. public class ContinueDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using continue statement i++; continue;//it will skip the rest statement } System.out.println(i); i++; }while(i<=10); } < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <hr></=10);></pre></=10){></pre></=3;i++){>

while 루프의 Java Continue 문

ContinueWhileExample.java

 //Java Program to demonstrate the use of continue statement //inside the while loop. public class ContinueWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using continue statement i++; continue; it will skip the rest } system.out.println(i); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <h2>Java Continue Statement in do-while Loop</h2> <p> <strong>ContinueDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of continue statement //inside the Java do-while loop. public class ContinueDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using continue statement i++; continue;//it will skip the rest statement } System.out.println(i); i++; }while(i<=10); } < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <hr></=10);></pre></=10){>

do-while 루프의 Java Continue 문

ContinueDoWhileExample.java

 //Java Program to demonstrate the use of continue statement //inside the Java do-while loop. public class ContinueDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using continue statement i++; continue;//it will skip the rest statement } System.out.println(i); i++; }while(i<=10); } < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <hr></=10);>