While Loop Usage in Java

Itacen Sabacok | Sep 7, 2021

if while condition is true, it continues to run.

1int x = 0
2while (x < 2) {
3  System.out.println(x);
4  x++;
5}

Do While Loop Usage

This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.

1int x = 0;
2do {
3  System.out.println(x);
4  x++;
5}
6while (x < 5);