Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- data structure
- DoM
- while
- DATAPATH
- javascript
- Java
- MIPS
- Class
- for
- instruction
- architecture
- html
- DB
- php
- DS
- react
- Algorithm
- Pipelining
- web
- CSS
- control
- github
- system
- mysql
- MacOS
- function
- XML
- computer
- python
- Linux
Archives
- Today
- Total
YYYEJI
[JAVA] While문이란? 본문
728x90
while문이란?
반복 횟수가 아닌 조건문으로 코드의 block을 반복시키고 싶을 때 사용하며,
Sentinel-controlled loop 또는 counting loop라고도 불립니다.
while (Boolean_Expression) {
Action_code;
}
public static void main(String[] args) {
String month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int i = 0;
while (month[i]!="December") {
System.out.println(month[i]);
i++;
}
}
while문의 조건문은 i번째 month의 값이 "December"가 아니면 코드를 반복하는 조건입니다.
while문이 반복되다가 index 11번째 month에 도착해서 값이 "December"이 되면 while문을 종료합니다.
"December"이 됐을 때는 while문이 종료되어 출력되지 않은 것을 확인할 수 있습니다.
◡̈
'Java' 카테고리의 다른 글
[JAVA] 객체 주소값 확인하기 (0) | 2022.12.24 |
---|---|
[JAVA] do-while문이란? (0) | 2022.12.24 |
[JAVA] For-each문이란? (0) | 2022.12.24 |
[JAVA] for문이란? (0) | 2022.12.24 |
[JAVA] Switch 문이란? (0) | 2022.12.24 |