logo

Јава Цонтинуе изјава

Наредба настављања се користи у структури контроле петље када треба одмах да пређете на следећу итерацију петље. Може се користити са фор петљом или вхиле петљом.

Тхе Јава наставак изјаве се користи за наставак петље. Наставља тренутни ток програма и прескаче преостали код под наведеним условом. У случају унутрашње петље, наставља само унутрашњу петљу.

Можемо користити Јава наставак наредбе у свим типовима петљи као што су фор петља, вхиле петља и до-вхиле петља.

Синтакса:

 jump-statement; continue; 

Пример Јава Цонтинуе изјаве

ЦонтинуеЕкампле.јава

 //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.

Јава Цонтинуе изјава са унутрашњом петљом

Наставља унутрашњу петљу само ако користите наредбу цонтинуе унутар унутрашње петље.

ЦонтинуеЕкампле2.јава

 //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++){>

Јава Цонтинуе изјава са означеном за петљу

Можемо користити наставак наредбе са ознаком. Ова функција је уведена од ЈДК 1.5. Дакле, сада можемо да наставимо било коју петљу у Јави било да је спољашња или унутрашња.

Пример:

јава стринг низа

ЦонтинуеЕкампле3.јава

 //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++){>

Јава Цонтинуе изјава у вхиле петљи

ЦонтинуеВхилеЕкампле.јава

 //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){>

Јава Цонтинуе изјава у до-вхиле петљи

ЦонтинуеДоВхилеЕкампле.јава

 //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);>