0% found this document useful (0 votes)
15 views3 pages

Class 11 JavaTransferOrJumpingStatements

Java jumping statements

Uploaded by

Rasool Shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Class 11 JavaTransferOrJumpingStatements

Java jumping statements

Uploaded by

Rasool Shaik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Transfer Statements: These are used to transfer control from one section to another

section. There are 3 different types of transfer statements.

1. break
2. continue
3. return

1. break: It is used only inside switch and any loop. Whenever break statement gets
executed, control comes out of immediate switch or loop.

Example-1: Inside simple loop

class Main{
public static void main(String[] args){
for(int i=1; i<=5; i++)
{
if(i == 3)
{
break;
}
System.out.print(i+" ");
}
}
}

Output:

1 2

Example-2: Inside nested loop

class Main{
public static void main(String[] args){
for(int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
System.out.print(j+" ");
if(i == j)
{
break;
}
}
System.out.println();
}
}
}

Output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

2. continue: It is used only inside loop. Whenever continute statement gets


executed, control skips the current iteration and moves to next iteration.
Example-1: Inside simple loop

class Main{
public static void main(String[] args){
for(int i=1; i<=5; i++)
{
if(i==2 || i==4)
{
continue;
}
System.out.print(i+" ");
}
}
}

Output:

1 3 5

Example-2: Inside nested loop

class Main{
public static void main(String[] args){
for(int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(i%2 == 0)
{
continue;
}
System.out.print((i+j)+" ");
}
System.out.println();
}
}
}

Output:

2 3 4 5 6

4 5 6 7 8

6 7 8 9 10

3. return: It is used in method to terminate the execution by returning a


value/without value.

class Main{
public static int max(int num1, int num2){
if(num1>num2)
return num1;
else
return num2;
}
public static void main(String[] args){
int num1 = 10;
int num2 = 13;
System.out.println(max(num1, num2));
}
}

Output:

13

You might also like