MCS-011 Problem Solving and Programming

First year, Semester 1

Chapters

Newsletter

THE goto STATEMENT

The goto statement is used to alter the normal sequence of program instructions by transferring the control to some other portion of the program. The syntax is as follows:

goto label;

Here, label is an identifier that is used to label the statement to which control will be transferred. The targeted statement must be preceded by the unique label followed by colon.

label : statement;

Although goto statement is used to alter the normal sequence of program execution but its usage in the program should be avoided. The most common applications are: 

  1.  To branch around statements under certain conditions in place of use of ifelse statement,
  2. To jump to the end of the loop under certain conditions bypassing the rest of statements inside the loop in place of continue statement,
  3. To jump out of the loop avoiding the use of break statement.

goto can never be used to jump into the loop from outside and it should be preferably used for forward jump.

Situations may arise, however, in which the goto statement can be useful. To the possible extent, the use of the goto statement should generally be avoided.  

Report an issue

Reporting: THE goto STATEMENT (topic)

Related Posts