- 반복문 내부에서 조건문(if)와 같이 사용하며, 조건이 맞는 경우(true) 이후 반복문 블럭 내부의 다른 수행문을 수행하지 않는다.
package ch04;
public class ContinueTest1 {
public static void main(String[] args) {
// continue 구문은 보통 반복문 내부에서 조건 (if) 와 함께 사용하며,
// 조건이 맞는 경우 (true) 이후 반복문 블럭 내부의 다른 수행문들을 수행하지 않는다.
// - 무시하고 진행하는 continue 이다.
// 1부터 100까지 숫자중에 3의 배수만을 출력
int num;
for (num = 1; num <= 100; num++) {
// 만약 num 값이 3의 배수가 아니라면 ??
// 3 /3 != 0 --> F
if (num % 3 != 0)
continue;
}
System.out.println("num : " + num);
}
}
package Exercise;
public class Exercise7 {
public static void main(String[] args) {
// 2. 1부터 10까지 숫자중에 홀수면 건너뛰고 짝수만 출력하시오.
// 출력 결과 예시
// 1은 홀수, 패스!
//짝수 : 2
// 3은 홀수, 패스!
// 짝수 : 4
// 5는 홀수, 패스!
// 짝수 : 6
// ...
int i;
for (i = 1; i <= 10; i++) {
if (i % 2 != 0) {
System.out.println(i + "은(는) 홀수, 패스!");
continue;
}
System.out.println("짝수 : " + i);
}
} // end of main
} // end of class