[Solved] how to use goto for this for loop? [closed]


First of all, that’s a weird way to put goto to use. You don’t need a goto at all and can just use a simple loop instead.

    for(int i = 0; i < 10; i++)
    {
        if(i == 5)
        {
            printf("Hello World ");
        }
        printf("%i ", i + 1);
    }

or if you really want to use goto for the sake of it, you can change it to

    int i = 0;
    for(i = 0; i < 10; i++)
    {
        if(i == 4)
        {
            goto point;
        }
        printf("%i ", i + 1);
    }

    point:
    printf("Hello World ");

    for(int i = 5; i < 10; i++)
    {
        printf("%i ", i + 1);
    }

and this is by no means a good code at all because it practically does the same thing as the previous one.

1

solved how to use goto for this for loop? [closed]