How to Break a Loop in Java


In this example we will show the method to break a loop in Java.

Source Code

package com.beginner.examples;

public class BreakLoop {
  public static void main(String[] args) {
    for (int k = 1; k < 4; k++) { // loop
      if (k == 3) break; // break
      System.out.println(k);
    }  
  }
}

Output:

1
2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments