From 696320fd2abe7cd072095e99aa29e474a6955194 Mon Sep 17 00:00:00 2001 From: Ily83 <90933947+Ily83@users.noreply.github.com> Date: Thu, 7 Aug 2025 21:41:08 +0200 Subject: [PATCH] [c,Eng] (#5362) * Update c.md fix goto https://github.com/adambard/learnxinyminutes-docs/issues/5293 * Update c.md Removed the variable bool this is for https://github.com/adambard/learnxinyminutes-docs/issues/5293 --- c.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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." */ /*