Labeled loops used in Java

In this topic, you will learn about, Labeled loops used in Java.

The labeled loop can be used with nested looping conditions. The labeled loop can be created for a while or do-while loop. Using this looping statement we can easily jump for a specified loop. So, we can also say that the labeled loop works the same as Goto’s statement.

In java, if you want to create a labeled loop you must specify the looping name or label, and if you want to jump the specified loop use labeled break or labeled continue statement.

<label 1>: for (i=0;i<=10;i++)
{
<label >: for (j=0;j<=10;j++)
{
System.out.print(’’ j’’);
Continue<label 2>;
}
}

Eg :
For (i=0;i<=10;i++)
{
B: for (j=0;j<=10;j++)
{
System.out.print(j);
Continue a;
}
}

Output:
0000000000

See also  History of Java