Computer Applications

Distinguish between the following:

continue statement and labelled continue statement

Java Nested for Loops

2 Likes

Answer

continue statementlabelled continue statement
continue statement is used to skip the current iteration of a loop and move on to the next iteration.A labelled continue statement skips the current iteration of an outer loop by using a label before the loop and including the same label in continue statement.
Syntax:
continue;
Syntax:
continue <label>;
For example,
for (int i = 0; i <= 3; i++)
{
System.out.println("i =" + i);
for(int j = 0; j < 3; j++)
{
if (i == 2)
{
continue;
}
System.out.print("j = " + j + " ");
}
System.out.println();
}
For example,
outerLoop:
for (int i = 0; i <= 3; i++)
{
for(int j = 0; j < 3; j++)
{
if (i == 2)
{
continue outerLoop;
System.out.println("i =" + i +" ; j =" + j);
}
}
}

Answered By

1 Like


Related Questions