public class MainClass {
    public static void main(String[] args) {
        /*
            while : 순환문
            do - while (참고로만 알아둘 것)

            형식:
                    변수선언 <- loop용 변수 int i
                    변수 초기화
                    while (조건) {
                        처리
                        연산식
                    }

                    변수선언 <- loop용 변수 int i
                    변수 초기화
                    do {
                        처리
                        연산식
                    } while (조건);
                    -> 조건이 안 맞아도 최소 1번은 실행된다.
         */
        int w;
        w = 0;

        while ( w < 10) {
            System.out.println("w = " + w);
            w++;
        }

//        // 무한루프
//        w = 0;
//        while (w >=0) {
//            System.out.println("w = " + w);
//            w++;
//        }

        // 무한루프 탈출: break
        w = 0;
        while (true) {
            System.out.println("w = " + w);
            if ( w == 100)  break;
            w++;
        }


        // 이중 while문
        int w1, w2;
        w1 = 0;

        while (w1 < 5) {
            System.out.println(" w1 = " + w1);
            w2 = 0;
            while (w2 < 3) {
                System.out.println("\t w2 = " + w2);
                w2++;
            }
            w1++;
        }


        // do while문
        int w3;
        w3 = 10;
        do {
            System.out.println("w3 = " + w3);
            w3++;
        } while (w3 < 10);
    }
}

+ Recent posts