freetimestudys@gmail.com          +91-7097633380
  Login Here                        

break Statement:

A break statement terminates the execution of the loop and the control is transferred to the statement immediately following the loop. i.e., the break statement is used to terminate loops 

Java Images

break means stop the execution come out of loop.

class Test
{
public static void main(String[] args)
  {
for (int i=0;i<10;i++)
 {
if (i==5)
 {
break;
 }
System.out.println(i);
 }
 }
}

intput and output

output:1,,2,,3,,4

2. The continue Statement

The continue statement is used to bypass the remainder of the current pass through a loop. 
 The loop does not terminate when a continue statement is encountered. Instead, the remaining loop statements are skipped and the computation proceeds directly to the next pass through the loop.

Java Images

continue program

class Test
{
public static void main(String[] args)
 {
for (int i=0;i<10;i++)
 {
if (i==5)
{
continue;
  }
System.out.println(i);
 }
 }
}

intput and output

output:0,,1,,2,,3,,4,,6,,7,,8,,9