Examveda
Examveda

Determine output:
public class Test{
        public static void main(String args[]){
                int i; 
                for(i = 1; i < 6; i++){ 
                        if(i > 3) continue ; 
                }
                System.out.println(i); 
        }
}

A. 2

B. 3

C. 4

D. 5

E. 6

Answer: Option E


This Question Belongs to Java Program >> Flow Control

Join The Discussion

Comments ( 8 )

  1. Ajay Bade
    Ajay Bade :
    2 years ago

    Ans 6 is correct because the println statement out of the for loop .first start the program i=1 inter in for loop but condition is i > 3 so counter will be increment and again enter in the loop the condition is false i will increment and again enter loop i = 3 but condition is false when i will be 4 the the i will continue and same as i = 6 loop condition is false the the i value is 6 thats why the i printed 6

  2. Thirupath Reddy
    Thirupath Reddy :
    3 years ago

    any one can explain i didn't understand

  3. Rishi Guha
    Rishi Guha :
    4 years ago

    The Answer will be 6, because if you look at the if statement it basically does nothing. The continue statement just iterates through the loop and increments the value of i. When i = 6 the loop terminates and S.O.P is executed.

  4. Pinaki Chakraborty
    Pinaki Chakraborty :
    4 years ago

    Ans is 2 , because if condition always skip values which is greater so 6 is skip value.

  5. Sasi Rekha
    Sasi Rekha :
    6 years ago

    Your Ans is wrong ..the Ans is 2...because if condition skip the values which are having greater than 3

  6. Rohan Pawar
    Rohan Pawar :
    6 years ago

    how come the answer corresponds to 6 when i

  7. Chaitanya V.
    Chaitanya V. :
    7 years ago

    Somebody help. I'm unable to understand why if condition is not evaluated.

  8. Whispher Eyes
    Whispher Eyes :
    7 years ago

    why we use here if condition while there is no effects it on there?

Related Questions on Flow Control