The goto
statement is a control flow statement in the C programming language that allows transferring control to a labeled statement within the same function or block of code.
goto label;
// ...
label:
// Statement(s) to be executed when the goto is used
The goto
statement is often considered discouraged and can lead to less readable and maintainable code. It should be used sparingly and carefully. When a goto
statement is encountered, it transfers control to the labeled statement specified by label
. The labeled statement is defined within the same function or block of code.
#include<stdio.h> int main() { int marks; label: printf("Enter the marks :\n"); scanf("%d",&marks); if(marks<0 || marks>100) { printf("Not valid Marks :\n"); goto label; } else { printf("Marks is : %d\n",marks); } }
Enter the marks : 88 Marks is : 88