What will be the result of attempting to compile and run the following program?
public class Main{ public static void main (String args []){ int i = 0; for (i=1 ; i<5 ; i++) continue; // (1) for (i=0 ; ; i++) break; // (2) for ( ; i<5?false:true ; ); // (3) } }
Select 1 option
Correct Option is : A
A continue statement can occur in and only in a for, while or do-while loop.
A continue statement means: Forget about the rest of the statements in the loop and start the next iteration.
So, for (i=1 ; i<5 ; i++) continue; just increments the value of i up to 5 because of i++.
for (i=0 ;___; i++) break; iterates only once because of the break so the value of i becomes 0.
for(___; i<5?false:true ; ); never iterates because i is less than 5 (it is 0 because of //2) and the condition expression is false!
At the end of the code, the value of i is 0.