Docsity

Break Statement in Java Programming Language, Exercises of Java Programming

Toggle sidebar
bg1
Break statement in java
Break statement in java
The
The break
break statement in Java programming language has the following two usages โˆ’
statement in Java programming language has the following two usages โˆ’
When the
When the break
break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement
statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement
following the loop.
following the loop.
It can be used to terminate a case in the
It can be used to terminate a case in the switch
switch statement (covered in the next chapter).
statement (covered in the next chapter).
Syntax
Syntax
The syntax of a break is a single statement inside any loop โˆ’
The syntax of a break is a single statement inside any loop โˆ’
break;
break;
Flow Diagram
Flow Diagram
pf2

Partial preview of the text

Download Break Statement in Java Programming Language and more Exercises Java Programming in PDF only on Docsity!

Break statement in javaBreak statement in java

The

The

break

break

statement in Java programming language has the following two usages โˆ’

statement in Java programming language has the following two usages โˆ’

When the

When the

break

break

statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement

statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement

following the loop.

following the loop.

It can be used to terminate a case in the

It can be used to terminate a case in the

switch

switch

statement (covered in the next chapter).

statement (covered in the next chapter).

SyntaxSyntax

The syntax of a break is a single statement inside any loop โˆ’The syntax of a break is a single statement inside any loop โˆ’

break;

break;

Flow Diagram

Flow Diagram

Example

Example

public

public class

class Test

Test {

public public staticstatic voidvoid mainmain((StringString argsargs[])[]) {{

int

int []

[]

numbers

numbers

for

for (

int

int x

x :

numbers

numbers )

if

if (

x

x

break break;;

System

System .

out

out .

print

print (

x

x );

System

System .

out

out .

print

print (

"\n"

"\n" );

This will produce the following result โˆ’

This will produce the following result โˆ’

Output

Output

Live Demo

Live Demo