You are on page 1of 12

CONTINUE,

GOTO AND
BREAK STATEMENT
THE CONTINUE SATEMENT
 Sometimes, in the iterations, it may be
necessary to skip some statements in that
loop and start the next iteration of that
same loop. For such situations, C provides
continue statement.
 The continue statement causes the loop
continue with the next iteration skipping the
remaining statement in that loop.
Do for(;;)
{ {
……………. ……………
if( ) if( )
continue; continue;
…………… ……………
…………… …………..
} while( ); }
EXAMPLE :
main()
{ int i;
for(i=1;i<=10;i++)
{
printf(“%d”,i);
if(i==3) continue;
printf(“ *** “);
}
}

Output of this program is as follows;

1 *** 2 *** 3 4 *** 5 *** 6 *** 7 *** 8 *** 9 *** 10 ***


THE BREAK STATEMENT:
 The break statement is used to jump out a
loop.
 An early exit from a loop can be
accomplished using the break statement.
 When a break statement is encountered inside a
loop, the loop is immediately exited and the
program continue with the statement
immediately following the loop.
 The general form are :

while(………) do for(…………)
{ {
{ ………… …………
………… ………… …………
………… if (condition) if (condition)
if (condition) break; break;
…………… ……………
break; …………. ………….
……………… } while(…………) }
………………. ………………… …………………
}
……………………
EXAMPLE:
Main()
{ int i;
for(i=1;i<=10;i++)
{
printf(“%d”,i);
if(i==3)break;
printf(“ *** “);
}
}
 Output of this program is as follows;

1*** 2 *** 3
THE GO TO STATEMENT
 The go to statement changes the normal
sequence of a the program execution by
transferring control to other part of the
program.
 The go to statement is usually not used
because C is completely structured language
and most probably, the break and continue
statements are used.
EXAMPLE:
Sample: …………..; //label
……………;
if( )
{
……………….;
break;
}
else
go to sample; //go to statement
EXAMPLE:
#include<stdio.h>
main()
{
aa:goto cc;
hum:printf(“the limit”);
goto end;
bb:printf(“\tSky”);
goto dd;
cc:printf(“\n\n The”);
goto bb;
dd:printf(“\tis”);
goto hum;
end:printf(“for the programmer”);
}
OUTPUT:
The Sky is the limit for the programmer

You might also like