C++ Jumping/Skipping Statement

  • Home
  • C++
  • C++ Jumping/Skipping Statement

Jumping statements are used to transfer the control from one point to another within the program.

Types of jumping statements:

break


  • break is a keyword.
  • It used with switch and looping statements.
  • It is used to transfer control out of the program from switch and looping statement
  • All statements after it are skipped and program control leaves the looping statement.


Program to show the use of break.



#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     for(int i=1;i<=6;i++)
     {
         if(i==3)
              break;
         cout<<"\n "<<i;         
     }
     getch();
}


Output

1
2


continue


  • continue is a keyword.
  • It is used with looping statement.
  • It is reverse of break statement.
  • It transfer control to next iteration in looping statement.
  • Statement written after continue are skipped and control goes to next iteration.

Program to use continue statement



#include<iostream.h>
#include<conio.h>
void main()
{
      clrscr();
      for(int i=1;i<=6;i++)
      {
           if(i==3)
                continue;
            cout<<"\n"<<i;
      }
      getch();
}


Output

1
2
4
5
6

Back To Top