What is the output of the following program?

Welcome to Java MCQ (Mulitple Choice Question) series. In this post, we will see one more quiz question on Java Loops.

What is the output of the following program?

public class Test{

	public static void main(String []args){
		int i = 0;
		for(i = 0; i < 10; i++){
			continue;
		}
		System.out.println(i);
	}
}
A. 10
B. 0
C. Compilation error
D. 9

Answer:

A. 10

Explanation:

Java continue keyword makes for-loop to skip the current iteration and continue with the next iteration. There will be a total of 10 iterations after which the value of variable i becomes 10 and that would make the for loop condition false. So finally the value of variable i is 10 after the loop hence Option A is correct.

Comments