goto statement transfers the control to the defined label and control will not return back after label execution it will go ahead and execute further statements.label must be inside the function.
Syntax
1 2 3 4 5 6 7 8 9 |
goto label; ... ... ... ..... ...... label: statement1; statement2; |
Flow Diagram:
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<stdio.h> int main() { unsigned int count=0; for(;count<10;count++) { if(count==4) { goto label; continue; } printf("\ncount=%d",count); } test: printf("Now Control at label test"); printf("\ncount=%d",count); printf("\ncount=%d",count); return 0; } |
1 2 3 4 5 6 7 8 9 |
Output: count=0 count=1 count=2 count=3 Now Control at label test count=4 count=4 |