what is the replacement for GOTO in java?
Answers were Sorted based on User's Feedback
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 |
What is difference between path and classpath variables?
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?
What is the difference between array and arraylist? what is the difference between arraylist and linkedlist?
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.........)
What are the differences between heap and stack memory?
Can we have multiple catch block for a try block?
What is an immutable object?
What is aggregation?
what is the use of bean managed and container managed with example?
What are the approaches that you will follow for making a program very efficient?