Java Break Statement Example

Chapter: Control Statements Last Updated: 06-07-2016 04:12:03 UTC

Program:

            /* ............... START ............... */
                
public class JavaBreakExample {
	public static void main(String args[]) {
		for (int i = 0; i < 100; i++) {
			if (i == 10)
				break; // terminate loop if i is 10
			System.out.println("i: " + i);
		}
		System.out.println("Loop complete.");
	}
}
                /* ............... END ............... */
        

Output

i: 0
i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
i: 8
i: 9
Loop complete.

Notes:

  • Break Statement in Java terminates the loop and comes out the loop when it is called.
  • Break statement used to terminate a case in the switch statement.
  • Break Statement is mostly used for for Loop, while Loop,switch statment and do-while loop.

Tags

Java break, Java

Similar Programs Chapter Last Updated
Java For Loop And ForEach Loop Example Control Statements 03-09-2016
Java Enum And Switch Statement Control Statements 03-09-2016
Control Statements In Java Example Control Statements 19-06-2016
If Statement In Java Example Control Statements 17-06-2016
Java Switch Example Control Statements 14-06-2016
While Loop In Java Example Control Statements 08-06-2017
Return Statement In Java example Control Statements 15-07-2016
Print Stars In Java Example Control Statements 15-07-2016
Nested Loop In Java Example Control Statements 15-07-2016
Infinite While Loop In Java Control Statements 10-06-2016
Infinite Loop In Java Example Control Statements 15-07-2016
If Else Statement In Java Example Control Statements 10-06-2016
For Loop In Java Example Control Statements 07-06-2017
For Each In Java Example Control Statements 07-06-2017
Do While Loop In Java Example Control Statements 10-06-2016
Continue Statement In Java Example Control Statements 30-03-2017

1