goto statement, Loop Control Statement, C Language Assignment Help

Assignment Help: >> Loop Control Statement >> goto statement, Loop Control Statement, C Language

goto statement

 A goto statement can transfer the control from current position to anywhere in the program. It is useful to provide branching within loops. Another use of goto statement is to exit from deeply nested loops where the break does not help. The general form of the goto statement is as follows:

while(conditional expression)

{             

if(condition1)

                                goto stop;

                statements;

                statements;

                statements;

                statements;

Exit

form

Loop

 
                statements;

                if(condition2)

Jump inside

Loop

 
                                goto abc;

                statements;

                statements;

                statements;

                abc:

                statements;

}

stop:

statements;

 

In different programming situations the goto statement is used to take the control anywhere we want.

The goto statement takes the control to the label specified with it. Any number of goto's can take the control to the same label. A program can contain more than one label but all the labels in a single program must be unique.

Example-

void main ( )

{

                                int a, b;

                                printf ("Enter two numbers");

                                scanf(""%d %d", &a, &b);

                                if (a > b)

                                                goto large;

                                else

                                                goto small;

                                large:

                                                printf ("Largest no. = %d and smallest no. = %d", a, b);

                                small:

                                                printf ("largest no. = %d and smallest no. = %d", b, a);

                                                goto end:

                                end:

                                                printf ("\n");

}

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd