ICSE Class 10 Computer Applications
Question 12 of 22
Nested for loops — Question 12
Back to all questions 12
Question Question 3(i)
Distinguish between the following:
break statement and labelled break statement
| break statement | labelled break statement |
|---|---|
| The break statement is used to take the control out of the loop control structure immediately enclosing it. | Labelled break statement transfers program control out of the code block whose label is specified as its target. |
Syntax:break; | Syntax:break <label>; |
| For example, for (int i = 1; i <= 3; i++) { for(int j = 1; j <= 2; j++) { if (i == 2) { break; } System.out.println("Iteration value of inner loop: " + j); } System.out.println(); } | For example, outer: for (int i = 1; i <= 3; i++) { for(int j = 1; j <= 2; j++) { if (i == 2) { System.out.println("Terminating the Outer-loop"); break outer; } System.out.println("i =" + i +" ; j =" + j); } |