Goto Statement in C

 


GOTO STATEMENT
Also called jump statement in c.
User to transfer program control to a predefine label.
Its used to avoided sinces it cause confusion for the fellow programmer in understanding the code.
Goto statement is preferable when we need to break multiples loops using a single command at the same time.

#include <stdio.h>
int main(){
    label:
    printf("We are inside the loop");
    goto end;
    printf("Hello World");
    goto label;
    end;
    printf("we are at end");
    return 0;
}

#include <stdio.h>
int main(int argcchar const *argv[])
{
    int num;
    for (int i = 0; i < 8; i++)
    {
        printf("%d", i);
        for (int j = 0; j < 8; j++)
        {
            printf("Enter 0 to exit\n");
            scanf("%d"&num);
            if (num == 0)
            {
                goto end;
            }
        }
    }
end:
    return 0;
}