While Loop

Loop executes the same block of code until the given condition is true. The condition is evaluated before the loop body is executed, so it's possible that the loop body may not execute at all if the condition is initially false.

Do while Loop

The do-while loop is similar to the while loop, but it guarantees that the loop body is executed at least once, regardless of whether the condition is initially true or false. After the loop body is executed, the condition is checked, and if it's true, the loop continues to execute.

Infinite Loop

The loop will be infinite if the condition is true and not becoming false.

Note: You can controll this infinite loop by pressing `Ctrl + c`.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

What will be the output?

15 XP~4 min
for(int i = 0; i < 3; i++) {
    System.out.print("%d ", i);
}
Exercise 2 of 2Easy

To exit a loop immediately, we use the ___ statement.

10 XP~2 min