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++){
			break;
		}
		System.out.println(i);
     }
}
A. 1
B. 0
C. 10
D. 9

Answer:

B. 0

Explanation:

When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.

The Java break statement is used to break the loop or switch statements. 

Comments