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);
}
}
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
Join The Discussion
Comments ( 8 )
Related Questions on Flow Control
What is the purpose of the "if" statement in Java?
A. To execute a block of code conditionally
B. To create loops
C. To declare variables
D. To define methods
A. No output
B. Error
C. Hello
D. 5
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
any one can explain i didn't understand
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.
Ans is 2 , because if condition always skip values which is greater so 6 is skip value.
Your Ans is wrong ..the Ans is 2...because if condition skip the values which are having greater than 3
how come the answer corresponds to 6 when i
Somebody help. I'm unable to understand why if condition is not evaluated.
why we use here if condition while there is no effects it on there?