Menu
Question Index
...

What will be the output of the following program?

class ForSample
{
    public static void main(String s[])
    {
        int i = 7;

        for(;;)
        {
            if( i < 4 ) break;
            System.out.println("i = " + i );
            i--;
        }
    }
}


i = 7
i = 6
i = 5
i = 4
i = 4
i = 5
i = 6
i = 7
Compilation error since no condition is present in the for loop.
No output since the body of the for loop is never executed.

Doubts

Problems

Topic: Using Break In for Loop To Exit

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App