Bắt đầu ngayBắt đầu miễn phí

Breaking Out

For the sake of demonstration, here is an example of usage of break in a code. Unfortunately, most real-world examples are a bit involved, and do not fit in an exercise.

Bài tập này là một phần của khóa học

Intermediate Java

Xem khóa học

Hướng dẫn bài tập

  • Use the proper keyword to stop the loop.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

class Breaker {
  public static void main(String[] args) {
    for (int i = 1; i < 64; i*=2) {
      System.out.println(i);
      if (i >= 8) {
        // Use the proper keyword to stop the loop
        ____;
      }
    }
    System.out.println("Broke out of the loop");
  }
}
Chỉnh sửa và Chạy Mã