변수의 초기화
do {
탈출 조건식이 참일 경우 실행되는 코드;
변수의 증감식;
} while (탈출 조건식);
*while문의 경우 탈출 조건식이 false를 반환하게 되면 한 번도 반복하지 않을 수도 있지만, do/while문의 경우 무조건 한 번은 실행하게 하고 싶을 때 사용한다.
public class DoWhileExam1 {
public static void main(String[] args) {
int i = 1;
do {
System.out.println(i);
i++;
} while(i <= 10);
}
}
1
2
3
4
5
6
7
8
9
10
public class DoWhileExam2 {
public static void main(String[] args) {
int i = 0;
do {
System.out.println(i);
i++;
} while (i < 1);
}
}
0