What will be printed out as a result of the following code execution?

public class TheLoop {
    public static void main(String...args) {
        int i = 1;
        do while(i < 1)
            System.out.println("i = " + ++i);
        while (i > 1);
    }
}
Explanation
Absence of braces complicates the understanding of the source code. Let's add them:

do {
     while (i < 1) {  // false when i = 1
         System.out.println("i = " + ++i);
     }
} while (i > 1);  // false when i = 1
Now it is obvious that the program will be executed successfully, but nothing will be printed out.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes