11th Computer Science 12th Computer Science CBSE JAC JAC

Jump statements in C++ with best example

Jump statements in C++ with best example
Written by AIPS

Jump statements are used to transfer the control form one part of the program to another part.

There are three jump statements in C++ programming language.

  1. break statement
  2. continue statement
  3. goto statement

Break Statement in C++

This statement is used for two purpose.

  1. To terminate loop permanently
  2. To exit from switch case

Q. write a program to represent break statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
if(i==5)
break;
cout<<”\n AIPS ACADEMY”;
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

OR

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
cout<<”\n AIPS ACADEMY”;

if(i==5)
break;
}
getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Find Output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{

if(i==5)
break;
cout<<”\n”<<i;

}
getch();
}

output

1

2

3

4

Find Output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=10; i++)
{
cout<<”\n”<<i;

if(i==5)
break;

}
getch();
}

Output

1

2

3

4

5

Continue Statement in C++

It is used to skip one execution of loop.

Q. write a program to represent continue statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=5; i++)
{

if(i==3)
continue;
cout<<”\n”<<i;

}
getch();
}

Output

1

2

4

5

Find output

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
for(i=1; i<=5; i++)
{
cout<<”\n”<<i;

if(i==3)
continue;

}
getch();
}

Output

1

2

3

4

5

Goto Statement in C++

It is used to transfer the control from one part of the program to another part.

It can also be used for repeat some statements.

syntax

goto label;

Q. Write a program to print your name five times using goto statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
i=1;
aips:
cout<<”\n AIPS ACADEMY”;
i++;
if(i<=5)
goto aips;

getch();
}

Output

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

AIPS ACADEMY

Q. Write a program to print numbers from 1 to 5 using goto statement.

#include<iostream.h>
#include<conio.h>
void main()  
{
clrscr();
int i;
i=1;
aips:
cout<<”\n”<<i;
i++;
if(i<=5)
goto aips;

getch();
}

Output

1

2

3

4

5

Also Read: Loop in C++

About the author

AIPS

Leave a Comment