How to use the goto statement to implement a loop in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    int i = 1;

START:
    if (i > 5)
        goto EXIT;

    printf("START %d\n", i);
    i++;
    goto START;

EXIT:
    printf("EXIT %d\n", i);

    return 0;
}



/*
run:

START 1
START 2
START 3
START 4
START 5
EXIT 6

*/

 



answered May 4, 2021 by avibootz

Related questions

1 answer 172 views
1 answer 147 views
2 answers 141 views
141 views asked Dec 17, 2023 by avibootz
1 answer 139 views
...