0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JAVAメモ―breakとcontinueの使い方

Last updated at Posted at 2023-12-04
class Main {
  public static void main(String[] args) {
    System.out.println("=== while文 ===");
    int i = 1;
    while (i < 10) {
      if(i % 5 == 0 ){
        break;
      }
      
      System.out.println(i);
      i++;
    }
    
    System.out.println("=== for文 ===");
    for (int j = 1; j < 10; j++) {
      if(j % 3 == 0 ){
        continue;
      }
      
      System.out.println(j);
    }
  }
}

結果:
=== while文 ===
1
2
3
4
=== for文 ===
1
2
4
5
7
8

break:処理を終了するため
continue:処理をスキップするため

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?