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

Why volatile is used in java?

0 Answers  


What do you mean by a JVM?

0 Answers   GE,


What initialize variables?

0 Answers  


Is there any case when finally will not be executed?

0 Answers  


Difference between static synchronization vs. Instance synchronization?

0 Answers  






where to use join method and explain with real time senario?and programatical explenation also..

1 Answers   TCS,


What is oop principle in java?

0 Answers  


explain the difference between jdk and jvm?

0 Answers  


What are voids?

0 Answers  


Does list allow duplicates in java?

0 Answers  


For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green &#61607; White will have 1 Weight. &#61607; Red and Green carry no weights. &#61607; Shortest path is the path with less weight when you add up the weights in the path.

0 Answers  


What is main string [] args?

0 Answers  






Categories