JUMPS STATEMENTS

These are also called as branching statements. These statements transfer control to another part of the program. When we want to break any loop condition or to continue any loop with skipping any values then we use these statements. There are three types of jumps statements.

1. Continue

2. Break

3. Goto

Continue

This statement is used within the body of the loop. The continue statement moves control in the beginning of the loop means to say that is used to skip any particular output.

Example:

WAP to print series from 1 to 10 and skip only 5 and 7.

#include

void main ( )

{

int a;

clrscr ( );

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

{

if (a= =5 | | a= = 7)

continue;

printf (“%d \n”,a);

}

getch ( );

}

Break

This statement is used to terminate any sequence or sequence of statement in switch statement. This statement enforce indicate termination. In a loop when a break statement is in computer the loop is terminated and a cursor moves to the next statement or block;

Example:

WAP to print series from 1 to 10 and break on 5

#include

void main ( )

{

int a;

clrscr ( );

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

{

if (a= =5)

break;

printf (“%d \n”,a);

}

getch ( );

}


Goto statement

It is used to alter or modify the normal sequence of program execution by transferring the control to some other parts of the program. the control may be move or transferred to any part of the program when we use goto statement we have to use a label.



WAP TO FIND IF NUMBER=10 THEN GOOD ELSE BAD

#include

void main ()

{

int a;

clrscr ();

printf ("Enter any Number: ");

scanf ("%d",&a);

if (a= =10)

goto g;

else

goto b;

g:

printf ("Good");

goto end;

b:

printf ("Bad");

goto end;

end:

getch ();

}


WAP TO PRINT SERIES FROM 1 TO 10

#include

void main ()

{

int a;

clrscr ();

a=1;

check:

if (a< =10)

goto inc;

else

goto end;

inc:

printf (“%d \n”,a);

goto check;

end:

getch ( );

}