Professional Documents
Culture Documents
Chapter 3.1 Cont Goto Break
Chapter 3.1 Cont Goto Break
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(“ *** “);
}
}
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