while 구문
while 반복문
형태
while(조건식){
실행코드
}실행 순서

데모 1 : 무한 반복

데모 2 : 10회 반복

데모 3 : 1부터 10까지 화면에 출력

데모 4 : 주사위 6이 나올 때까지 랜덤값 출력
Last updated
while(조건식){
실행코드
}



Last updated
import java.lang.*;
public class WhileExample01 {
public static void main(String[] args){
while(true){
System.out.println("Hello world");
}
}
}import java.lang.*;
public class WhileExample02 {
public static void main(String[] args){
int n = 1;
while(n <= 10){
System.out.println("Hello World!");
n++;
}
}
}import java.lang.*;
public class WhileExample03 {
public static void main(String[] args){
int n = 1;
while(n <= 10){
System.out.println("숫자 : " + n);
n++;
}
}
}import java.lang.*;
import java.util.Random;
public class WhileExample04 {
public static void main(String[] args){
Random r = new Random();
while(true){
int dice = r.nextInt(6)+1;
System.out.println("주사위 = " + dice);
if(dice == 6){
break;
}
}
}
}