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 do negative exponents mean?

539


What does singleton mean in java?

504


What is e in java?

535


Lowest Common ancestor in a Binary Search Tree and Binary Tree.

548


When should we create our own custom exception classes?

574






Differentiate between static and non-static methods in java.

555


What is java developer skills?

500


What is this keyword in java?

556


How you can force the garbage collection?

533


Give me some null interfaces in java?

594


how can you take care of mutual exclusion using java threads? : Java thread

599


What is another word for methodology?

514


From the two, which would be easier to write: synchronization code for ten threads or two threads?

606


What is nullpointerexception?

549


What is the difference between sop and work instruction?

476