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 are field variable and local variable?

3 Answers  


How can we create a thread in java?

0 Answers  


Name the package that always imported by default?

4 Answers  


How do you define a set in java?

0 Answers  


where singleton classes are used in j2ee web application.can we use it for connection pooling.

1 Answers  






Difference between Choice and a List?

1 Answers  


What is the difference between instanceof and isinstance?

0 Answers  


What are methods?

0 Answers  


What do you understand by Header linked List?

0 Answers   Genpact,


Which Java operator is right associative?

3 Answers  


What do you know about the garbage collector?

0 Answers  


what is synchronization

3 Answers  


Categories