Showing posts with label break statement in java. Show all posts
Showing posts with label break statement in java. Show all posts

Monday, 3 December 2018

Jumping statement in java | break statement in java | continue statement in java - Online Help

Jumping statement:

Statement or loops perform a set of operations continue until the condition variable will not satisfy the condition. but if we want to break the loop when the condition will satisfy then java give permission to jump from one statement to end of the loop or beginning of loop as well as jump out of the loop.
- break statement
- continue statement

Break statement:

Break statement is used to terminate from a loop while the test condition is true.This statement can be used within a while,do-while,for and switch statement.The general format is:
                                             break;
program:
class breakdemo
{
public static void main(String args[])
{
for(int i=0;i<100;i++)
{
if(i==10)
break;
System.out.println("i="+i);
}
}
}

The output is:
i=0
i=1
i=2
i=3
i=4
i=5
i=6
i=7
i=8
i=9


Continue statement:

  The continue statement is used to skip the remaining statement in the loop. The general format is:
                                                  continue;

Program:
class continuedemo
{
public static void main(String args[])
{
for(int i=2;i<20;i++)
{
if(i%2=0)
continue;
System.out.println("i="+i);
}
}
}

The output is:
i=0
i=2
i=4
i=6
i=8
i=10
i=12
i=14
i=16
i=18