what is the replacement for GOTO in java?

Answer Posted / devesh dashora

break with label and continue with label.
1. Break with label
loop1: for (int i = 0; i < 10; i++)
{
loop2: for ( int j = 0; j < 10; j++)
{
System.out.println(i);
if( i + j > 10 )
break loop1;
}
}

2. continue with label

loop1: for (int i = 0; i < 10; i++)
{
loop2: for ( int j = 0; j < 10; j++)
{
if(i + j == 5)
continue loop1;
System.out.println(j);
}
}

Is This Answer Correct ?    12 Yes 20 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is boolean used for?

774


extending thread class or implementing runnable interface. Which is better? : Java thread

774


Why set do not allow duplicates in java?

752


How many types of operators are there?

711


Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.

1801


What is e in java?

719


What does java final mean?

709


What is literal example?

718


Explain the importance of finally over return statement?

806


How do we access static members in java?

824


What is the use of list in java?

721


Explain about interthread communication and how it takes place in java?

762


Mention a package that is used for linked list class in java.

720


Which oo concept is achieved by using overloading and overriding?

726


What are the two environment variables that must be set in order to run any java programs?

710