ICSE Class 9 Computer Applications Question 13 of 17

Nested for loops — Question 13

Back to all questions
13
Question

Question 4(i)

Distinguish between the following:

break statement and labelled break statement

Answer
break statementlabelled break statement
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);
}