logo

Јава Бреак изјава

Када се унутар петље наиђе на наредбу бреак, петља се одмах прекида и контрола програма се наставља на следећој изјави која следи након петље.

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

у јава регуларном изразу

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

Синтакса:

 jump-statement; break; 

Дијаграм тока изјаве о прекиду

дијаграм тока јава бреак изјаве

Јава Бреак изјава са петљом

Пример:

БреакЕкампле.јава

 //Java Program to demonstrate the use of break statement //inside the for loop. public class BreakExample { public static void main(String[] args) { //using for loop for(int i=1;i<=10;i++){ if(i="=5){" breaking the loop break; } system.out.println(i); < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement with Inner Loop</h2> <p>It breaks inner loop only if you use break statement inside the inner loop.</p> <p> <strong>Example:</strong> </p> <p> <strong>BreakExample2.java</strong> </p> <pre> //Java Program to illustrate the use of break statement //inside an inner loop public class BreakExample2 { 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 break statement inside the break; } 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 Break Statement with Labeled For Loop</h2> <p>We can use break statement with a label. The feature is introduced since JDK 1.5. So, we can break any loop in Java now whether it is outer or inner loop.</p> <p> <strong>Example:</strong> </p> <p> <strong>BreakExample3.java</strong> </p> <pre> //Java Program to illustrate the use of continue statement //with label inside an inner loop to break outer loop public class BreakExample3 { 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 break statement with label aa; } system.out.println(i+' '+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 </pre> <h2>Java Break Statement in while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the while loop. public class BreakWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using break statement i++; break; it will the loop } system.out.println(i); < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement in do-while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the Java do-while loop. public class BreakDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using break statement i++; break;//it will break the loop } System.out.println(i); i++; }while(i<=10); } < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement with Switch</h2> <p>To understand the example of break with switch statement, please visit here: <a href="/java-switch-statement">Java Switch Statement</a> .</p> <hr></=10);></pre></=10){></pre></=3;i++){></pre></=3;i++){></pre></=10;i++){>

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

Разбија унутрашњу петљу само ако користите наредбу бреак унутар унутрашње петље.

Пример:

БреакЕкампле2.јава

 //Java Program to illustrate the use of break statement //inside an inner loop public class BreakExample2 { 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 break statement inside the break; } 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 Break Statement with Labeled For Loop</h2> <p>We can use break statement with a label. The feature is introduced since JDK 1.5. So, we can break any loop in Java now whether it is outer or inner loop.</p> <p> <strong>Example:</strong> </p> <p> <strong>BreakExample3.java</strong> </p> <pre> //Java Program to illustrate the use of continue statement //with label inside an inner loop to break outer loop public class BreakExample3 { 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 break statement with label aa; } system.out.println(i+\' \'+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 </pre> <h2>Java Break Statement in while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the while loop. public class BreakWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using break statement i++; break; it will the loop } system.out.println(i); < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement in do-while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the Java do-while loop. public class BreakDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using break statement i++; break;//it will break the loop } System.out.println(i); i++; }while(i<=10); } < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement with Switch</h2> <p>To understand the example of break with switch statement, please visit here: <a href="/java-switch-statement">Java Switch Statement</a> .</p> <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 break outer loop public class BreakExample3 { 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 break statement with label aa; } system.out.println(i+\' \'+j); < pre> <p> <strong>Output:</strong> </p> <pre> 1 1 1 2 1 3 2 1 </pre> <h2>Java Break Statement in while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the while loop. public class BreakWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using break statement i++; break; it will the loop } system.out.println(i); < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement in do-while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the Java do-while loop. public class BreakDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using break statement i++; break;//it will break the loop } System.out.println(i); i++; }while(i<=10); } < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement with Switch</h2> <p>To understand the example of break with switch statement, please visit here: <a href="/java-switch-statement">Java Switch Statement</a> .</p> <hr></=10);></pre></=10){></pre></=3;i++){>

Јава Бреак изјава у вхиле петљи

Пример:

БреакВхилеЕкампле.јава

 //Java Program to demonstrate the use of break statement //inside the while loop. public class BreakWhileExample { public static void main(String[] args) { //while loop int i=1; while(i<=10){ if(i="=5){" using break statement i++; break; it will the loop } system.out.println(i); < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement in do-while loop</h2> <p> <strong>Example:</strong> </p> <p> <strong>BreakDoWhileExample.java</strong> </p> <pre> //Java Program to demonstrate the use of break statement //inside the Java do-while loop. public class BreakDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using break statement i++; break;//it will break the loop } System.out.println(i); i++; }while(i<=10); } < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement with Switch</h2> <p>To understand the example of break with switch statement, please visit here: <a href="/java-switch-statement">Java Switch Statement</a> .</p> <hr></=10);></pre></=10){>

Јава Бреак изјава у до-вхиле петљи

Пример:

БреакДоВхилеЕкампле.јава

рхел вс центос
 //Java Program to demonstrate the use of break statement //inside the Java do-while loop. public class BreakDoWhileExample { public static void main(String[] args) { //declaring variable int i=1; //do-while loop do{ if(i==5){ //using break statement i++; break;//it will break the loop } System.out.println(i); i++; }while(i<=10); } < pre> <p> <strong>Output:</strong> </p> <pre> 1 2 3 4 </pre> <h2>Java Break Statement with Switch</h2> <p>To understand the example of break with switch statement, please visit here: <a href="/java-switch-statement">Java Switch Statement</a> .</p> <hr></=10);>

Јава Бреак изјава са Свитцх

Да бисте разумели пример бреак са свитцх наредбом, посетите овде: Јава Свитцх изјава .