Loading

In the do-while loop, we execute the statement first before checking the given condition or expressions. So the do block will execute at least once whether the condition is true or false.


Syntax:

do{
   //code
}
while (condition);


Example:

package quipohouse;
public class DoWhileLoop {
	public static void main(String[] args) {
		int i = 1;
		do {
			System.out.println(i);
			i++;
		} while (i <= 5);
	}
}


Output:

1
2
3
4
5

Key Point

  • Executes the block before checking the condition.
  • Ensures the loop runs at least once.
  • Useful when you need at least one iteration before condition checking.