logo

بيان كسر جافا

عند مواجهة عبارة فاصل داخل حلقة، يتم إنهاء الحلقة على الفور ويستأنف التحكم في البرنامج في العبارة التالية التي تلي الحلقة.

جافا استراحة يتم استخدام العبارة لكسر الحلقة أو يُحوّل إفادة. إنه يكسر التدفق الحالي للبرنامج في حالة محددة. في حالة الحلقة الداخلية، فإنه يكسر الحلقة الداخلية فقط.

أمر grep في لينكس

يمكننا استخدام عبارة Java Break في جميع أنواع الحلقات مثل لحلقة , حائط اللوب و افعل بينما حلقة .

بناء الجملة:

 jump-statement; break; 

مخطط انسيابي لبيان الاستراحة

مخطط انسيابي لبيان كسر جافا

بيان كسر جافا مع الحلقة

مثال:

BreakExample.java

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

بيان كسر جافا مع الحلقة الداخلية

يتم كسر الحلقة الداخلية فقط إذا كنت تستخدم عبارة Break داخل الحلقة الداخلية.

مثال:

BreakExample2.java

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

بيان فاصل Java مع تسمية للحلقة

يمكننا استخدام بيان الاستراحة مع التسمية. تم تقديم الميزة منذ الإصدار JDK 1.5. لذلك، يمكننا كسر أي حلقة في جافا الآن سواء كانت حلقة خارجية أو داخلية.

مثال:

BreakExample3.java

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

بيان كسر جافا في أثناء الحلقة

مثال:

BreakWhileExample.java

 //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 في حلقة do-while

مثال:

BreakDoWhileExample.java

إلغاء تثبيت الزاوي cli
 //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);>

بيان كسر جافا مع التبديل

لفهم مثال عبارة Break with Switch، يرجى زيارة هنا: بيان تبديل جافا .