Goto Statement in C Language
In the C programming language, the goto statement is used to transfer control to a labeled statement within the same function or block of code. It allows you to jump from one part of your code to another, which can be useful in certain situations. However, the use of goto is generally discouraged and considered bad practice because it can lead to hard-to-read and error-prone code. In structured programming, it's recommended to use control structures like loops and conditional statements (if-else) to control the flow of your program instead of using goto.
Here's the basic syntax of the goto statement in C:
goto is the keyword.
label is an identifier that marks the destination where you want to jump.
Here's an example of how you can use goto:
In this example, a label named start is defined before an if statement. The program uses goto to jump back to the start label as long as the condition i < 5 is true. This code will print the numbers from 0 to 4.
Again, it's important to note that using goto should
be avoided in most cases because it can make your code less readable
and harder to maintain. Instead, use structured programming constructs
like loops (e.g., for, while, do-while) and conditional statements
(e.g., if, else) to control the flow of your program.
All C Topics : -
- C Language Intro
- Structure of C Language
- Variable & data Types
- Printf and Scanf Function
- Operator in c Language
- If Statement in c Language
- If else and Nasted if in C
- Switch Case In C
- While loop in C Language
- Exit Control Loop (Do While)
- For Loop in c
- C Language Pratice Program
- Goto Statement in c Programming
- Array in c
- Pointer in c Language
- String in c Language