C Syntax of goto Statement
C Syntax of goto Statement
The goto
statement in C is used to transfer control unconditionally to a specified label within the same function. Here's the syntax and an explanation for each step:
- Syntax:
c goto label; // ... label: statement;
The goto
statement is followed by the label to which the control is transferred. The label is defined by placing a colon (:) after it.
- Explanation:
- The
goto
keyword is used to initiate the transfer of control. label
is the target label where the control will be transferred.- The label is followed by a colon (:) to indicate that it is a label.
- After the label, the statement to be executed is written.
The goto
statement should be used judiciously as its misuse can make the code less readable and harder to maintain. It is often considered a controversial feature in programming languages due to its potential to create complex and hard-to-follow control flows.