Home » Java programming language

break statement in java with example

In this java tutorial, we are going to learn about 'break' statement. How and when a break statement is used, we will learn using example here?
Submitted by IncludeHelp, on November 29, 2017

break statement is used to break the execution of any loop or to break (come out from particular case body) the switch cases in switch statement.

break statement interrupts the flow of loop at certain conditions, in case of multiple loops, break statement only break that loop in which break is used.

Syntax of break statement


The syntax is a simple break keyword, used within the loop body or after the switch case statements.

Let’s understand with this flow chart:

break statement in java

Image reference: https://www.programiz.com/c-programming/c-break-continue-statement

Example of break statement

public class breakstate {
	public static void main(String arg[]){
		int i;



In this program, the loop is running from 1 to 12 and we are using break inside the if condition (i==8). So, when value of i will be 8, loop execution will be stopped and program’s execution will jump to the next statement written just after the loop body.

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.