Java의 continue 문

Haider Ali 2023년10월12일
Java의 continue 문

이 가이드는 Java에서 continue 문 사용에 관한 모든 것입니다. 그것은 무엇입니까? 어떻게 작동합니까? 언제 이 문장을 사용해야 합니까? 이 모든 것이 이 짧은 가이드에 설명되어 있습니다. 뛰어들어봅시다.

Java의 continue

루프에서 continue 문을 주로 사용합니다. Java에서 이 명령문은 break 명령문처럼 작동합니다. 유일한 차이점은 루프를 종료하지 않는다는 것입니다. 대신 continue 문 아래의 코드를 실행하지 않고 루프가 다음 반복을 실행하도록 합니다. 아래에 제공된 코드 스니펫을 살펴보세요.

public class Main {
  public static void main(String args[]) {
    for (int i = 0; i < 100; i++) {
      if (i % 2 != 0) {
        continue; //  SKip the Iteration If Number IS Odd;
      }
      System.out.print(i + ", ");
    }
  }
}

코드의 결과는 어떻게 될까요? 홀수를 인쇄합니까? 대답은 ‘아니오. 조건 내부에는 아래의 전체 코드를 건너뛰면서 루프를 다음 반복으로 점프하는 continue 문이 있기 때문입니다.

작가: Haider Ali
Haider Ali avatar Haider Ali avatar

Haider specializes in technical writing. He has a solid background in computer science that allows him to create engaging, original, and compelling technical tutorials. In his free time, he enjoys adding new skills to his repertoire and watching Netflix.

LinkedIn

관련 문장 - Java Statement