Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
C: Goto statement


1. C: Goto statement


This page summarizes the operational behavior of some common control structures used in, say, the C programming language.

For more detailed information, see C: Goto statement .

2. Statements and expressions
In the following:

3. Labels
The target of a goto statement (on memory or in a program) is represented by a label.
L10: L20: L30: L40:

A label starts with a letter and is followed by letters and/or digits followed by a colon character.

4. Unconditional goto statement
An unconditional goto statement has the following form.
   goto label ;

When executed, it will transfer control to the first statement that follows label.

5. Conditional goto statement
The conditional goto statement has the following form.
   if ( expression ) goto label ;

and, when executed, if expression is true, then control is transferred to the first statement that follows label.

6. Control structures
Some common control structures are presented in two parts.

7. If then else statement
Here is the general syntax of the "if then else" statement
if ( expression ) {    statements    } else {    statements    }

Here is the equivalent goto form.
L10:    if( ! expression ) goto L20;    statements    goto L30; L20:    statements L30:


8. If then statement
Here is the general syntax of the "if then" statement
if (expression) {    statements    }

Here is the equivalent goto form.
L10:    if( ! expression ) goto L20;    statements L20:


9. While do statement
Here is the general syntax of the "while do" statement
while ( expression ) {    statements    }

Here is the equivalent goto form.
L10:    if( ! expression ) goto L20;    statements    goto L10; L20:


10. Do while statement
Here is the general syntax of the "do while" statement
do {    statements    } while ( expression );

Here is the equivalent goto form.
L10:    statements    if( expression ) goto L10; L20:


11. End of page

12. Multiple choice questions for this page