what is the replacement for GOTO in java?

Answers were Sorted based on User's Feedback



what is the replacement for GOTO in java?..

Answer / firoz

continue

Is This Answer Correct ?    10 Yes 17 No

what is the replacement for GOTO in java?..

Answer / 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

More Core Java Interview Questions

What is difference between path and classpath variables?

0 Answers  


In Java why we write public static void main(String args[]) why not main()?

46 Answers   Aptech, GE Healthcare, Infosys, Microsoft, New Horizon, Practical Viva Questions, TCS, Wipro,


Can we define constructor in inner class?

0 Answers  


What is the difference between array and arraylist? what is the difference between arraylist and linkedlist?

8 Answers   EDS, Matrix,


If a multi threaded Java program has started numerous number of threads, at any point in time how to know which thread is currently executing/running ?

7 Answers   Accenture, College School Exams Tests, iFlex, NIIT,






what is actual real time using of oops concepts in projects(Interface,polymorphism.abstraction.........)

2 Answers  


What are the differences between heap and stack memory?

0 Answers  


Can we have multiple catch block for a try block?

0 Answers  


What is an immutable object?

0 Answers  


What is aggregation?

1 Answers   Cap Gemini,


what is the use of bean managed and container managed with example?

0 Answers   EDS,


What are the approaches that you will follow for making a program very efficient?

0 Answers  


Categories