Loading....
Coupon Accepted Successfully!

 

Jump Statement

  • This jump statements helps to have a immediate local transfer of the control
  • There are many types of jump statements available. They are
    • Goto statement
    • Break statement
    • Continue statement

Goto Statement

  • It transfers the program control anywhere in the program.
  • It is identified with a help of a label.
  • The general format is
Statement;

Labeled-statement;

Jump statement;

Jump statement;

goto identifier;

labeled statement;

identifier: statement;

  • It performs unconditional transfer of control to the named label.
  • The label must be the current function.
  • A jump statement must be inside the same function and can appear before only one statement in the same function.
  • The label cannot be redeclared.

For example

 

main()

{

goto next;

char ch ='a';

-----

-------

next:

--------

-------

}

Break Statement

  • This statement terminates the execution of the nearest enclosing loop or conditional statement in which it appears.
  • Control passes to the statement that follows the terminated statement.
  • This statement is used in switch case as a main statement.
  • The general format
loop

{

break;

code....

}

Program 8: test program for break statement.

#include <iostream.h>

void main()

{

int i;

for (i = 1; i < 10; i++)

{

cout<<"\n"<< i;

if (i == 4)

break;

}

}

Note: Break statement terminates the process temporarily.

Continue Statement

  • This a type of jump statement which skips some statement over a part of the code.
  • The general format 
{

Statement1;

if(Condition statement)

continue;

statement2;

}

  • This statement can be used in any conditional statements.
  • For example in for loop, if loop and in while loop.

Program 9: Example for continue statement

#include <iostream.h>

main()

{

int i = 0;

do

{

i++;

cout<<"before the continue\n";

continue;

cout<<"after the continue, should never print\n";

}

while (i < 3);

cout<<"after the do loop\n";

}

Note: The continue statement abandons the current iteration of the loop by skipping over the rest of the statements body in the loop body.





Test Your Skills Now!
Take a Quiz now
Reviewer Name