Write about Labeled loops in Java

Labeled loops:

In java we can give a label to a block of statements a label is any valid java variable name. to give a label to a loop, place it before the loop with a colon(:) at the end.

For eg:

loop1: for(……..)
{
…………..
…………..
}

A block of statements can be labeled as shown below.

Block2:
{
…………..
…………...
Block 2:
{
…………..
…………..
}
………….
…………..
}

We have seen that simple break statement causes the control to jump outside the nearest loop and a simple continue statement restarts the current loop. If we want to jump outside a nested loops or to continue a loop. i. e outside the current one then we may have to use the labeled break and labelled continue statements.

Eg:

 outer: for(int m=1; m < 10; m++)
{
for(int n=1; n < 10;n++)
{
System.out.println(“ “+m*n);
if(m==n)
continue outer;
}
}


Here they continue statement terminates the inner loop when m==n and continuous with the next iteration of the outer loop.

Related

Features of Java

Java is  simple  and  familiar   program  language:- learning and practicing java  is easy because it contains many features of c and c++. Java is  s...

Explain Data Types in Java?

Every  variable  in java  has  a  data type.  Data  type specify the  size of the memory occupied   and  type  of   va...

Program for Demonistrating LIFE CYCLE OF APPLET

import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.applet.*; public class App extends Applet implements ActionListener {       &nb...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item