Jump Statements in Java

Jump statement are used to alter the flow of control unconditionally. That is, jump statement transfer the program control unconditionally. The jump statement defined in Java are break, continue and return.

Break Statement…

The break statement is extensively used in loops and switch statement. It immediately terminates the loop or the switch statement, by passing the remaining statement. The control then passes to the statement that immediately follows the loop or the switch statement.

Continue Statement…

The continue statement is used to continue the loop with its next iteration. In other words, it skips any remaining statements in the current iteration and immediately passes the control to the next iteration.

Return Statement…

The return statement is used to transfer the control out of the method explicitly. It transfers the control back to the caller and terminates the method in which it is present. When the return statement is encountered in the main()method, it transfers the control back to the Java run-time system and terminates the program execution.

Example1...

class allloops

{

public static void main(String aa[])

{

LOOP1:for(int i=1;i<50;i++)

{

System.out.println(" @");

if(i==10)

break;

for(int j=1;j<50;j++)

{

System.out.println("*****");

if(j==1)

continue LOOP1;

}}

System.out.println("XCnotes.com ");

}}

Jump Statement in Java

 Example 2..

class jump

{

public static void main(String aa[])

{

int factor=0,number=10,sum=0;

System.out.println("Number="+number);

while(true)

{

factor++;

if(factor>number)

break;

if(number%factor!=0)

continue;

sum=sum+factor;

}

System.out.println("sum of factor="+sum);

if(sum>0)

return;

System.out.println("Statement is not executed");

}

}

Jump Staement in Java

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @