Home     Blog

goto Statement

In programming, significance has always been given to use of structured programming technique to build reliable software that are easy to debug, maintain and modify. In some cases, performance is more important than strict obedience to structured programming technique. In these cases, some unstructured programming technique may be used.

For example, we can use break to terminate execution of a repetition structure before the loop continuation condition becomes false. This saves unnecessary repetition of the loop if the task is completed before loop termination.

Another instance of unstructured programming is the use of goto statement, which is an unconditional branch. The result of the goto statement is a change in the flow of control of the program to the first statement after the label specified in the goto statement. A label is an identifier followed by a colon (:). A label must appear in the same function as the goto statement that refers to it.

Example: Program to show the execution of goto statement

goto statement clip image002 goto Statement

Output:

goto statement clip image004 goto Statement

The goto statement can be used to exit deeply nested control structures efficiently.

It should be used only in performance oriented applications. It is unstructured and can lead to programs that are more difficult to debug, maintain, and modify.

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
Follow Daniel Memetic on

Leave a Reply

Related Posts

  • break and continue Statements

    break Statement The break statement is used to alter the flow of control. When a break statement is executed in a while loop, for loop, do-while loop or switch statement, it causes immediate exit from that statement. Program execution continues with the next statement. Common uses of the break statement are to escape early from [...]...


  • if Statement

    An if/else statement tests a particular condition, if the condition evaluates to true, a course-of-action is followed i.e. a statement or a set of statements is executed. Otherwise another set of instructions are executed (the else block). Such statements are called program control statements that control the flow of execution in a program. Normally, the [...]...


  • Iterations

    An Iteration involves repeating some portion of a program, a specified number of time or until a particular condition is satisfied. This repetitive operation in C and C++ is achieved through for, while and do-while loop. How does a for loop work? A for loop is the easiest iteration loop to understand the C and [...]...


  • Inline Function

    One of the main objectives of using functions in a program is to save some memory space, which becomes appreciable when a function is likely to be called many times. However, every time a function is called, it takes a lot of extra time in executing a series of instructions for task such as jumping [...]...


  • Conditional Operators and Switch Statements

    C++ has an operator that can be used as an alternative to an if-statement. This operator is called the conditional operator (?:). This operator can be used to replace an if-else statement of the following general form: if(expression) {      statements ;      -      - } else {      statements ;      -      - } The above form of [...]...