Menu
Topics Index
...
`

Continue


If you need explanation Read this topic

If you need Answer Take test on this topic

Continue
What will be the output of the following program?
class DemoOnLabel
{
    public static void main(String args[])
    {
        outer : for (int first = 0; first < 3; first++)
        {
            for (int second = 3; second >= 0; second--)
            {
                if (first == second)
                    continue outer;
                System.out.println(first + " " + second);
             }
          }
     }
}

A. 0 3
0 2
0 1
1 3
1 2
2 3
B. 0 2
0 3
1 3
2 3
0 1
1 2
C. 0 2
0 1
0 3
1 3
2 3
1 2
D. 0 2
0 1
1 2
2 3
1 3
0 3
E. Compilation Error or Runtime Error
Topic: Java continue Statement

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

option A
Intially first=0,second=3..
repeates inner loop so
0 3
0 2
0 1
later first=0 and second=0 exits loop and continues to outer ..
prints 1 3
1 2
again exits the inner loop and first is incremented
prints 2 3
as first=2,second=2 exits inner loop and also exits outer loop as first incremented by 1 i.e first=3

Posted by Sasikanth Sharma    2014-09-01 08:37:11


ans A, first and second will equal at '0' and next equal at "1" and finally equal at "2" when they equal inner loop wont iterate so it jumps to outer loop. remaining all are printed successfully.

Posted by Damu Surya    2014-09-01 09:18:19


Ans: A  when we use continue only the current loop will be turminated , so the loop will be executed until the condition satified .so the loop comparision will be goes <0,3 0,2 0,1 1,3 1,2 > here 1,1 get satisfied so it is not printed and then control will goes to outer loop then <2,3>is executed and then <2,2>condition satified so it will not printed.so output is  option A;

Posted by Sapparapu Pradeep Kumar    2014-09-01 10:34:59


ans is A ,, outer is worked as labled continue here,,,

Posted by Raju VarshnEy    2014-09-01 12:17:03


Congratulations Sasikanth Sharma. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-02 05:12:04


© meritcampus 2019

All Rights Reserved.

Open In App