keyword

The break keyword in Java programming language

The break keyword in Java programming language

In this tutorial, we will discuss The break keyword in Java programming language.

the break is a keyword in Java programming language which causes the loop to terminate or to exit execution of for loop, while loop, do-while loop and switch case statements.

When the break statement is used in a loop, the loop terminates immediately during execution.

Declaration

The syntax of break statements given below

break;
break keyword in Java

Break in while loop

while(.....){
//loop statements
break;
}

break statement how to use while loop

public class Break_Key{
public static void main(String args[]){
int count=1;
while(count<=10)
{
System.out.println(count);
if(count==5){
break;
}
count++;
}

}

}

 

 

When the above code is executed, it produces the following results

1
2
3
4
5

 

Break in for loop

for(.....){
//loop statements
break;
}

break statement how to use for loop

public class Break_Key1{
public static void main(String args[]){
int count;
for(count=1; count<=10; count++ )
{
System.out.println(count);
if(count==4){
break;
}

}

}

}

 

When the above code is executed, it produces the following results

1
2
3
4

 

Break in switch nstatements

switch(.....){
//case statements 1
break;
//case statements 2
break;
..........
..........
}

break statement how to use switch statements

public class SwitchKey{
public static void main(String args[]){
int age=18;
switch(age){
case 1: System.out.println("Baby");
break;
case 5: System.out.println("child");
break;
case 10: System.out.println("boy");
break;
case 15: System.out.println("student");
break;
case 18: System.out.println("teen ager");
break;
default:System.out.println("man");

}
}

When the above code is executed, it produces the following results

teen ager

 

There are other Java language keywords that are similar to this keyword

 byte  in Java Language

 int  in Java Language

long  in Java Language

 float  in Java Language

char  in Java Language

 void  in Java Language

try  in Java Language

Catch in Java Language

implements  in java Language

public  in Java Language

static  in Java language

Volatile  in Java Language

Package  in Java Language

class  in Java Language

boolean  in Java Language

break in Java Language

do  in Java Language

double  in Java Language

This  in Java Language

final  in Java Language

switch  in Java Language

interface  in Java Language

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Finally  in Java language

The abstract keyword in Java language
The public keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

  • This is pretty great post. I´ve been thinking of starting a blog on this subject myself.

    Best regards,
    Thompson Hessellund

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago