• 欢迎光临~

Java: Break and Continue

开发技术 开发技术 2022-11-24 次浏览

Break: the "break" stops the loop

for (int i = 0; i < 10; i++) {
  if (i == 1) {
    break;
  }
  System.out.println(i);
}

// Outputs
0

Continue: The continue statement breaks one iteration

for (int i = 0; i < 5; i++) {
  if (i == 2) {
    continue;
  }
  System.out.println(i);
}

// Outputs
0
1
3
4

 

程序员灯塔
转载请注明原文链接:Java: Break and Continue
喜欢 (0)