Computer Applications

Distinguish between the following:

break statement and labelled break statement

Java Nested for Loops

4 Likes

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

Answered By

2 Likes


Related Questions