diff --git a/c.md b/c.md index 99e0c06a..cba76dc8 100644 --- a/c.md +++ b/c.md @@ -387,22 +387,23 @@ int main (int argc, char** argv) /* Using "goto" in C */ - typedef enum { false, true } bool; - // for C don't have bool as data type before C99 :( - bool disaster = false; int i, j; for(i=0; i<100; ++i) for(j=0; j<100; ++j) { - if((i + j) >= 150) - disaster = true; - if(disaster) - goto error; // exit both for loops + if((i + j) >= 150) { + goto error; // exit both for loops immediately + } } + printf("No error found. Completed normally.\n"); + goto end; + error: // this is a label that you can "jump" to with "goto error;" printf("Error occurred at i = %d & j = %d.\n", i, j); + end: + return 0 /* - https://ideone.com/GuPhd6 + https://ideone.com/z7nzKJ this will print out "Error occurred at i = 51 & j = 99." */ /*