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.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback