웹개발 교육/Java

[30일] Java (10) - 반복문

ewok 2022. 9. 6. 13:23

for

//1. for문
for(int a=1; a<=3; a++) {
	System.out.println("JAVA");
}//for end

//for문에 선언된 변수는 for문에서만 사용 가능하다
//System.out.println(a);  에러

int b=0;
for(b=1; b<=3; b++) {
	System.out.println("PYTHON");
}//for end

System.out.println(b);

while

//2. while문
int i=0;
while(i<=3) {
	System.out.println("SEOUL");
	i++;
}//while end

 

do ~ while

//3. do~while문
int j=0;
do {
	System.out.println("JEJU");
	j++;
}while(j<=3);

break와 continue

//4. break와 continue문
for(int a=1; a<10; a++) {
	if(a==5) {
		break;
	}//if end
	System.out.print(a + " ");
}//for end

System.out.println(); //줄바꿈

for(int a=1; a<10; a++) {
	if(a==5) {
		continue;
	}//if end
	System.out.print(a+ " ");
}//for end