Java Labelled For Loop.
What is Labeled for loop in Java?
Labeled for loop have nothing newer than the label. In labeled for loops before starting every for loop we give the label to that for the loop.
What is the label in for loop of Java and its syntax?
The label is the same as the labels on the Switch case. Any valid identifier of the label followed by the : sign is valid for the label.
What is the use of labeled for loop in Java?
In normal nested for loop if you put the break statement in the inner for loop. When break statement executes it only terminate the execution of the inner for loop.
But what if you want to terminate the execution of the outer for loop with the break statement in the inner for loop?
Then this special type of for loop comes in the picture. It terminates the execution of the loop which is associated with the label.
Java Simple and Labeled For Loop and Output
If you find the post is useful and informative then share with your friends on social media using the social media icons below.
Please don’t forget to subscribe to Code Puran newsletters to get the post like this in your mailbox.