티스토리 뷰

Language/JAVA

java do while

KyeongRok Kim 2018. 5. 2. 16:27

java do while


do while은 while문과는 다르게 최소한 한번은 실행 되는 while문이다.


do{} 블록 안에 있는 내용이 최소한 한번 실행 된다.


1
2
3
4
5
6
7
8
public class DoWhileExam {
    public static void main(String[] args) {
        do {
            System.out.println("hello");
        } while (false);
    }
}
 
cs


결과

 hello



1
2
3
4
5
6
7
8
public class DoWhileExam {
    public static void main(String[] args) {
        do {
            System.out.println("hello");
        } while (true);
    }
}
 
cs

결과

hello

hello

hello

hello

hello

hello

hello

hello

hello

··· 생략 ··· 


대딩때 배웠는데 배우고 나서 8년만에 처음 써보는 것 같다. ㅋㅋ


왜냐하면 일단 while문을 거의 안쓴다. 주로 for each를 쓴다.


그리고 while문은 멀티스레드 환경에서 사이드 이펙트가 있어서 특정 상황에서만 주로 쓰기 때문에 잘 안썼던 것.


 end.



공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함