Notice
Recent Posts
Recent Comments
관리 메뉴

Developer Gonie

[1주차] 18. 반복을 위한 while문(반복횟수를 구체화하기 힘든경우 보통 사용) 본문

K-DigitalTraining 강의/1. Java

[1주차] 18. 반복을 위한 while문(반복횟수를 구체화하기 힘든경우 보통 사용)

이대곤 2022. 5. 19. 12:17

While 코드(전 비교 조건반복문)

public class Ex03_12_while {

	public static void main(String[] args) {
		int i = 1;
		while (i <= 10) {
			System.out.print(i);
			i++;
		}
	}
}

실행결과

12345678910

Do While 코드(후 비교 조건반복문)

* while문과 다른점은 i 값이 10보다 큰 값이라도 일단은 안으로 들어가서 실행됨.

public class Ex03_12_while {

	public static void main(String[] args) {
		int i = 1;
		
		do {
			System.out.print(i);
			i++;
		}while(i <= 10);
	}
}

실행결과

12345678910
Comments