JAVA BREAK STATEMENT
INTRODUCTION
The break and continue statements are used to control the program flow and we can use these statements in a loop to control the loop iteration process.
These two statements (Break and Continue) gives us power to control the loop and switch statements by enabling us to either break out loop and jump to the next iteration by skipping the current loop iteration.
BREAK STATEMENT SYNTAX
for(statement ...)
{
if(condition ...)
{
break;
}
}
PROGRAM FOR BREAK STATEMENT
class break_statement
{
public static void main(String args[])
{
int i;
for(i=1; i<=10; i++)
{
System.out.println(i);
if(i == 6)
{
break;
}
}
System.out.println("Break statement excuted ...");
}
}
BREAK STATEMENT SYNTAX
for(statement ...)
{
if(condition ...)
{
break;
}
}
PROGRAM FOR BREAK STATEMENT
class break_statement
{
public static void main(String args[])
{
int i;
for(i=1; i<=10; i++)
{
System.out.println(i);
if(i == 6)
{
break;
}
}
System.out.println("Break statement excuted ...");
}
}
- - - PROGRAM OUTPUT - - -
0 Comments