do-while
What is a Do-while loop?
- 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