The goto Statement:


The goto requires a label in order to identify the place where the branch is to be made. A label is any valid variable name, and must be followed by a colon (:). The label is placed immediately before the statement where the control is to be transferred. The general forms of goto and label statements are shown below:


The label can be anywhere in the program either before or after the goto label; statement. Note that a goto breaks the normal sequential execution of the program. If the label: is before the statement goto label; a loop will be formed and some statements will be executed repeatedly. Such a jump is known as backward jump.
            On the other hand, if the label: is placed after the goto label; some statements will be skipped and the jump is known as a forward jump.

Applications of goto statement:
1.      The goto statement is basically used to skip or repeat a set of statements.
2.      It is used to exit from deeply nested loops when an error occurs.


Previous                                                                                    Next


Powered by Blogger.