Jump Statements in C: break, continue and goto Statements Notes in Hindi & English : जंप स्टेटमेंट्स: break, continue (वर्तमान चक्र छोड़ना) और goto और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Jump Statements in C: break, continue and goto Statements (जंप स्टेटमेंट्स: break, continue (वर्तमान चक्र छोड़ना) और goto) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: C provides break, continue, and goto (alongside return) as unconditional jump statements that alter sequential control flow inside blocks, loops, and functions. break exits the innermost loop or switch, continue skips the remainder of the current iteration, and goto jumps to a label strictly within the same function.

अध्याय सार: C भाषा में break, continue और goto (तथा return) अनकंडीशनल जंप स्टेटमेंट्स हैं जो ब्लॉक, लूप व फंक्शन के क्रमिक प्रवाह को तुरंत बदलते हैं। break सबसे आंतरिक लूप या switch से बाहर निकालता है, continue वर्तमान चक्र का शेष भाग छोड़ देता है, और goto एक ही फंक्शन के भीतर किसी लेबल पर जंप करता है।

Jump Statements in C: break, continue and goto Statements: Detailed Notes & Architecture (जंप स्टेटमेंट्स: break, continue (वर्तमान चक्र छोड़ना) और goto)

1. break Statement: Innermost Loop & switch Termination (break स्टेटमेंट: आंतरिक लूप व switch समाप्ति)

[EN] Executing break; terminates only the single innermost enclosing loop (for, while, do-while) or switch statement, transferring control to the first statement immediately after that construct. A single break never exits two nested loops simultaneously, and placing break outside any loop or switch raises a compile-time error. Notably, when a switch sits inside a for loop, executing break inside a case exits only the switch—not the enclosing for loop.

[HI] break; केवल अपने सबसे नजदीकी आंतरिक लूप (for, while, do-while) या switch स्टेटमेंट को तुरंत समाप्त करता है और नियंत्रण उस संरचना के ठीक बाद वाले स्टेटमेंट पर ले जाता है। एक break कभी दो नेस्टेड लूप्स से एक साथ बाहर नहीं निकलता, तथा लूप या switch के बाहर इसे लिखना कंपाइल एरर देता है। ध्यान रहे कि यदि किसी for लूप के भीतर switch हो, तो switch का break केवल switch से बाहर निकालेगा, for लूप से नहीं।

2. continue Statement: Iteration Skipping Across Loop Types (continue स्टेटमेंट: वर्तमान चक्र छोड़ने के नियम)

[EN] The continue keyword applies strictly to loops—placing it inside a standalone switch causes a compile error, while inside a switch nested in a loop it skips the remainder of the outer loop's body. Crucially, continue jumps to different targets depending on the loop construct: in while and do-while loops it jumps directly to the while(condition) test (which can cause infinite loops if the update statement was skipped!), whereas in a for loop it always executes the update expression (expr3) before re-testing the condition.

[HI] continue केवल लूप्स में ही मान्य है; अकेले switch में यह कंपाइल एरर देता है, जबकि लूप के अंदर स्थित switch में उपयोग होने पर यह बाहरी लूप का वर्तमान चक्र छोड़ देता है। महत्वपूर्ण अंतर यह है कि while व do-while में continue सीधे while(condition) जांच पर ले जाता है (जिससे अपडेट छूटने पर अनंत लूप बन सकता है), जबकि for लूप में यह पहले update भाग (expr3) को चलाकर फिर शर्त जांचता है।

3. goto Statement: Function-Local Labels & Cleanup Idioms (goto स्टेटमेंट: लेबल नियम व सुरक्षित उपयोग)

[EN] The statement 'goto label;' jumps unconditionally forward or backward to 'label: stmt;' within the exact same function body; C prohibits jumping across functions via goto (inter-function jumps require setjmp/longjmp in <setjmp.h>). Labels reside in their own separate namespace from variables and carry function scope. Although backward spaghetti gotos harm readability (as Dijkstra famously critiqued), forward goto remains idiomatic in systems code like the Linux kernel for breaking out of deeply nested loops and centralizing error-cleanup (goto cleanup;).

[HI] goto label; एक ही फंक्शन के भीतर आगे या पीछे स्थित किसी लेबल पर अनकंडीशनल जंप करता है; अलग-अलग फंक्शनों के बीच goto की अनुमति नहीं है। C में लेबल्स का अपना स्वतंत्र नेमस्पेस होता है, अतः वे वेरिएबल्स से नाम नहीं टकराते। यद्यपि बिना सोचे-समझे पीछे की ओर goto लिखना 'स्पैगेटी कोड' बनाता है, फिर भी लिनक्स कर्नेल जैसे सिस्टम कोड में गहरे नेस्टेड लूप्स से निकलने और एरर-क्लीनअप (goto cleanup;) के लिए आगे की ओर goto बहुत उपयोगी माना जाता है।

4. Jump Scope Restrictions, VLA Limits & return Contrast (जंप स्कोप सीमाएँ, VLA नियम व return तुलना)

[EN] In C99/C11, jumping via goto from outside into the scope of a Variable Length Array (VLA) is strictly illegal at compile time, while jumping past normal scalar variable initializers bypasses initialization and leaves garbage values. Also, prior to C23, a label cannot appear right before a closing brace '}' without at least a null statement ';' (such as end:;). Unlike break (exits construct) and goto (stays inside function), return exits the entire enclosing function and returns control to the caller.

[HI] C99/C11 में किसी वेरिएबल लेंथ एरे (VLA) के स्कोप के बाहर से उसके भीतर goto से कूदना कंपाइल एरर है, और सामान्य वेरिएबल्स के इनिशियलाइजेशन को कूदकर छोड़ देने से उनमें गार्बेज मान रह जाता है। साथ ही C23 से पहले किसी ब्लॉक के अंतिम '}' से ठीक पहले बिना नल स्टेटमेंट ';' के अकेला लेबल (end:;) लिखना अवैध था। जहाँ break लूप तोड़ता है और goto फंक्शन में ही रहता है, वहीं return पूरे फंक्शन को समाप्त कर देता है।

Syntax, Formula & Technical Example (Jump Statements in C: break, continue and goto Statements)

for (int i = 1; i <= 5; i++) {
    if (i == 2) continue; // Skips printf, runs i++
    if (i == 4) break;    // Exits loop at i = 4
    printf("%d ", i);     // Output: 1 3
}
if (1) goto cleanup;      // Forward jump within same function
printf("Unreachable\n");
cleanup:
printf("Done\n");

Jump Statements in C: break, continue and goto Statements Quick Reference & Comparison Table

Jump StatementPermitted Enclosing ContextControl Flow Effect
breakInnermost loop or switch statementExits construct completely to next statement
continueLoops only (for, while, do-while)Skips remaining body; hits update in for or cond in while
goto labelAny statement inside the same functionUnconditional jump to function-scoped label
return [val]Anywhere inside a function bodyTerminates entire function and resumes caller

Jump Statements in C: break, continue and goto Statements Top 20 Bilingual MCQs with Answers

Q1. When 'break;' executes inside the inner loop of two nested for loops, what happens?

(दो नेस्टेड for लूप्स के आंतरिक लूप में 'break;' चलने पर क्या होता है?)

(A) The entire program exits immediately

(B) Only the current iteration skips like continue

(C) Both inner and outer loops terminate together

(D) Only the inner loop terminates; the outer loop continues its next pass

Correct Answer: (D)

[EN] break always breaks out of the single innermost enclosing loop or switch statement.

[HI] break हमेशा केवल सबसे नजदीकी आंतरिक लूप या switch से बाहर निकलता है; बाहरी लूप सामान्य रूप से चलता रहता है।

Q2. What happens when running: int i = 0; while (i < 5) { if (i == 2) continue; printf("%d", i); i++; }?

(कोड 'int i = 0; while (i < 5) { if (i == 2) continue; printf("%d", i); i++; }' चलाने पर क्या होगा?)

(A) Prints 01 and exits cleanly

(B) Prints 01 and then hangs in an infinite loop

(C) Prints 01234

(D) Prints 0134

Correct Answer: (B)

[EN] At i = 2, continue skips printf and i++, jumping back to while (i < 5) with i stuck at 2 forever!

[HI] i = 2 होने पर continue नीचे लिखे i++ को भी छोड़ देता है और सीधे while(i<5) पर लौट आता है, जिससे 01 प्रिंट होकर अनंत लूप बन जाता है।

Q3. What is the output of: for (int i = 1; i <= 5; i++) { if (i == 3) continue; printf("%d ", i); }?

('for (int i = 1; i <= 5; i++) { if (i == 3) continue; printf("%d ", i); }' का आउटपुट क्या होगा?)

(A) 1 2 3 4 5

(B) Infinite loop

(C) 1 2 4 5

(D) 1 2

Correct Answer: (C)

[EN] Unlike while, continue inside a for loop jumps to the update clause i++ before re-testing i <= 5, so 3 is skipped cleanly.

[HI] for लूप में continue हमेशा i++ अपडेट भाग पर जाता है, अतः केवल 3 छूटता है और 1 2 4 5 प्रिंट होता है।

Q4. What occurs if 'continue;' appears inside a switch statement that is NOT nested inside any loop?

(यदि बिना किसी लूप के सीधे switch के अंदर 'continue;' लिखा जाए, तो क्या होगा?)

(A) Jumps back to switch(expr)

(B) Compile-time error ('continue statement not within a loop')

(C) Skips to default case

(D) Acts identically to break

Correct Answer: (B)

[EN] continue works exclusively with iteration loops (for, while, do-while), never standalone switch constructs.

[HI] continue केवल लूप्स पर लागू होता है; बिना बाहरी लूप के अकेले switch में इसे लिखने पर कंपाइल एरर आता है।

Q5. If a switch sits inside a for loop and a case executes 'break;', what exits?

(यदि किसी for लूप के भीतर स्थित switch के एक case में 'break;' चले, तो क्या समाप्त होगा?)

(A) The function returns immediately

(B) Only the switch statement; the enclosing for loop keeps iterating

(C) Only the current case falls through

(D) Both switch and for loop terminate

Correct Answer: (B)

[EN] break binds strictly to the nearest enclosing switch or loop, which here is the switch.

[HI] break केवल सबसे आंतरिक switch को समाप्त करेगा, बाहरी for लूप अपना अगला चक्र जारी रखेगा।

Q6. Can a C 'goto' statement jump from function funcA() directly to a label defined inside funcB()?

(क्या मानक C में 'goto' द्वारा funcA() से किसी दूसरे फंक्शन funcB() के लेबल पर जंप किया जा सकता है?)

(A) Yes, if the label is declared extern

(B) Yes, if both functions are in the same .c file

(C) Yes, using goto funcB::label

(D) No, goto labels have function scope and jumping across functions fails to compile

Correct Answer: (D)

[EN] C strictly limits goto jumps to the same function; non-local jumps across stack frames require setjmp()/longjmp().

[HI] goto का दायरा केवल उसी फंक्शन तक सीमित है; अलग फंक्शनों के बीच जंप कंपाइल एरर देता है (इसके लिए setjmp/longjmp होते हैं)।

Q7. In ISO C, what happens if a local variable and a goto label share the same name inside one function (e.g., int x = 5; x: ...; goto x;)?

(यदि एक ही फंक्शन में लोकल वेरिएबल और goto लेबल का नाम समान हो (जैसे int x = 5; x: ...; goto x;), तो क्या होगा?)

(A) goto modifies variable x to 0

(B) It compiles cleanly because labels occupy a separate namespace in C

(C) Runtime ambiguity fault

(D) Compile-time redeclaration error for x

Correct Answer: (B)

[EN] C places label names in their own independent namespace separate from ordinary identifiers, tags, and struct members.

[HI] C भाषा में लेबल्स का नेमस्पेस वेरिएबल्स से बिल्कुल अलग होता है, इसलिए दोनों एक ही नाम के साथ बिना किसी त्रुटि के चल सकते हैं।

Q8. Why did placing a label directly before a closing brace 'void f(void) { goto end; end: }' fail in C99/C11 unless written 'end: ;'?

(C99/C11 में '}' से ठीक पहले अकेला लेबल 'end: }' लिखने पर कंपाइल एरर क्यों आता था (जब तक 'end: ;' न लिखा जाए)?)

(A) Labels in C99/C11 must precede a statement (like ';'), not a closing brace '}'

(B) goto cannot jump forward inside void functions

(C) Labels cannot be named 'end' in C

(D) Every label must contain a return statement

Correct Answer: (A)

[EN] Adding a semicolon creates a null statement attached to the label, satisfying C99/C11 syntax (relaxed later in C23).

[HI] C99/C11 में लेबल के बाद एक वैध स्टेटमेंट होना जरूरी था; ';' लगाने से वह नल स्टेटमेंट बन जाता है।

Q9. Which jump via goto is forbidden at compile time in C99/C11?

(C99/C11 में goto के द्वारा इनमें से कौन सी छलांग कंपाइल-टाइम पर वर्जित है?)

(A) Jumping backward to repeat a block

(B) Jumping to a cleanup label inside the same function

(C) Jumping from outside into the scope of a Variable Length Array (VLA)

(D) Jumping forward out of a doubly nested for loop

Correct Answer: (C)

[EN] Entering the scope of a VLA via goto bypasses its runtime size allocation and is explicitly prohibited by C99/C11.

[HI] VLA (वेरिएबल लेंथ एरे) के स्कोप के बाहर से अंदर goto से कूदना C99/C11 में पूरी तरह अवैध है।

Q10. In professional C codebases like the Linux kernel, which use of goto is widely considered clean and idiomatic?

(लिनक्स कर्नेल जैसे पेशेवर C कोड में goto का कौन सा उपयोग स्वच्छ और मानक माना जाता है?)

(A) Backward jumps replacing all while and for loops

(B) Forward jumps to break out of deeply nested loops or reach centralized error cleanup

(C) Jumping into the middle of if blocks from below

(D) Replacing function calls with goto labels

Correct Answer: (B)

[EN] Forward cleanup jumps avoid duplicated free()/close() calls and deeply nested boolean exit flags.

[HI] गहरे नेस्टेड लूप्स से बाहर आने या फंक्शन के अंत में केंद्रीकृत मेमोरी/संसाधन क्लीनअप (Forward Jump) के लिए goto उपयोगी माना जाता है।

Q11. How does 'return;' inside a while loop differ fundamentally from 'break;'?

(while लूप के भीतर 'return;' और 'break;' के प्रभाव में मूल अंतर क्या है?)

(A) return jumps to the loop condition

(B) break terminates the entire program, return exits only the loop

(C) Both behave identically inside main()

(D) return terminates the entire function, whereas break exits only the while loop

Correct Answer: (D)

[EN] After break, statements following the loop inside the same function still execute; return jumps straight back to the caller.

[HI] break केवल लूप समाप्त करके उसी फंक्शन की अगली लाइन पर जाता है, जबकि return पूरे फंक्शन को समाप्त कर कॉलर के पास लौट जाता है।

Q12. What happens if 'break;' is written inside an if statement that is NOT enclosed within any loop or switch?

(यदि किसी ऐसे if ब्लॉक में 'break;' लिखा जाए जो किसी लूप या switch के अंदर नहीं है, तो क्या होगा?)

(A) It terminates the enclosing function

(B) It exits the main program

(C) It exits the if block cleanly

(D) Compile-time error ('break statement not within loop or switch')

Correct Answer: (D)

[EN] break cannot break out of a standalone if statement; it requires an enclosing loop or switch.

[HI] break का उपयोग स्वतंत्र if ब्लॉक से बाहर निकलने के लिए नहीं किया जा सकता; इसके लिए लूप या switch होना आवश्यक है।

Q13. What is the output of: for (int i = 0; i < 6; i++) { if (i % 2 == 0) continue; if (i == 5) break; printf("%d ", i); }?

('for (int i = 0; i < 6; i++) { if (i % 2 == 0) continue; if (i == 5) break; printf("%d ", i); }' का आउटपुट क्या होगा?)

(A) 1 2 3 4

(B) 0 2 4

(C) 1 3 5

(D) 1 3

Correct Answer: (D)

[EN] Even values 0, 2, 4 trigger continue; 1 and 3 print; at i = 5, break exits before printf.

[HI] i=0, 2, 4 सम होने पर continue से छूटते हैं, 1 और 3 प्रिंट होते हैं, और i=5 पर break लूप खत्म कर देता है: उत्तर 1 3।

Q14. Trace the output: int x = 0; do { x++; if (x == 2) continue; printf("%d ", x); } while (x < 3);

('int x = 0; do { x++; if (x == 2) continue; printf("%d ", x); } while (x < 3);' का आउटपुट क्या होगा?)

(A) 1

(B) 1 2 3

(C) 1 3

(D) Infinite loop

Correct Answer: (C)

[EN] x=1 prints 1; x=2 triggers continue jumping to while(2<3) (true); x=3 prints 3, then while(3<3) stops.

[HI] x=1 पर 1 प्रिंट; x=2 पर continue नीचे while(x<3) शर्त पर जाता है जो सत्य है; फिर x=3 पर 3 प्रिंट होकर लूप रुकता है।

Q15. Which statement is NOT true about C jump statements?

(C जंप स्टेटमेंट्स के बारे में इनमें से कौन सा कथन असत्य है?)

(A) A single break statement exits all nested loops containing it simultaneously

(B) goto jumps strictly within the same function

(C) continue skips only the remaining statements of the current iteration

(D) return exits the entire current function

Correct Answer: (A)

[EN] break exits only the innermost enclosing loop or switch; exiting multiple nested loops requires flags, functions, or goto.

[HI] एक break स्टेटमेंट सभी बाहरी नेस्टेड लूप्स से एक साथ बाहर नहीं निकलता, बल्कि केवल सबसे आंतरिक लूप या switch को ही तोड़ता है।

Q16. Who wrote the famous 1968 letter 'Go To Statement Considered Harmful' advocating structured loops over unrestricted goto?

(1968 में 'Go To Statement Considered Harmful' लेख लिखकर अनियंत्रित goto के विरुद्ध संरचित लूप्स की वकालत किसने की थी?)

(A) Dennis Ritchie

(B) Edsger W. Dijkstra

(C) Brian Kernighan

(D) Bjarne Stroustrup

Correct Answer: (B)

[EN] Dijkstra's 1968 CACM letter sparked the structured programming movement built around sequence, selection, and iteration.

[HI] एड्सगर डब्ल्यू. डिजक्स्ट्रा ने 1968 में यह ऐतिहासिक लेख लिखकर स्ट्रक्चर्ड प्रोग्रामिंग को बढ़ावा दिया था।

Q17. Within Jump Statements in C: break, continue and goto Statements, which jump statement directly maps to: "Innermost loop or switch statement"?

(Jump Statements in C: break, continue and goto Statements में कौन सा Jump Statement सीधे "Innermost loop or switch statement" से संबंधित है?)

(A) break

(B) continue

(C) return [val]

(D) goto label

Correct Answer: (A)

[EN] In Jump Statements in C: break, continue and goto Statements, 'break' handles 'Innermost loop or switch statement' (Exits construct completely to next statement).

[HI] Jump Statements in C: break, continue and goto Statements में 'break' का कार्य/विवरण 'Innermost loop or switch statement' (Exits construct completely to next statement) है।

Q18. Which option accurately describes 'continue' in Jump Statements in C: break, continue and goto Statements?

(Jump Statements in C: break, continue and goto Statements के संदर्भ में 'continue' की सही विशेषता कौन सी है?)

(A) Innermost loop or switch statement

(B) Anywhere inside a function body

(C) Loops only (for, while, do-while)

(D) Any statement inside the same function

Correct Answer: (C)

[EN] 'continue' provides 'Loops only (for, while, do-while)' — key point: Skips remaining body; hits update in for or cond in while.

[HI] 'continue' का मुख्य विवरण 'Loops only (for, while, do-while)' है (Skips remaining body; hits update in for or cond in while)।

Q19. In Jump Statements in C: break, continue and goto Statements, identify the correct parameter for the specification: "Any statement inside the same function".

(Jump Statements in C: break, continue and goto Statements में "Any statement inside the same function" विवरण किस विकल्प के लिए सही है?)

(A) return [val]

(B) break

(C) goto label

(D) continue

Correct Answer: (C)

[EN] 'goto label' corresponds to 'Any statement inside the same function' (Unconditional jump to function-scoped label).

[HI] 'goto label' का संबंध 'Any statement inside the same function' (Unconditional jump to function-scoped label) से है।

Q20. Considering Jump Statements in C: break, continue and goto Statements, what key behavior defines 'return [val]'?

(Jump Statements in C: break, continue and goto Statements में 'return [val]' की मुख्य भूमिका या मान क्या है?)

(A) Anywhere inside a function body

(B) Innermost loop or switch statement

(C) Any statement inside the same function

(D) Loops only (for, while, do-while)

Correct Answer: (A)

[EN] 'return [val]' represents 'Anywhere inside a function body' (Terminates entire function and resumes caller).

[HI] 'return [val]' का अर्थ/मान 'Anywhere inside a function body' है (Terminates entire function and resumes caller)।

Jump Statements in C: break, continue and goto Statements — Exam FAQs

Q1: Why does continue inside a while loop risk an infinite loop more easily than inside a for loop?

for लूप की तुलना में while लूप में continue से अनंत लूप बनने का खतरा अधिक क्यों रहता है?

[EN] In a for loop, continue transfers control to the update expression before re-testing the condition; in a while loop, the update statement usually resides inside the body, so jumping straight to the condition test can skip the update permanently.

[HI] for लूप में continue शर्त जांचने से पहले अपडेट एक्सप्रेशन चलाता है, जबकि while लूप में अपडेट बॉडी के अंदर होता है—इसलिए continue से अपडेट छूटकर वेरिएबल अटक सकता है।

Q2: When is using goto considered good practice in C?

C प्रोग्रामिंग में goto का उपयोग कब अच्छा या व्यावहारिक माना जाता है?

[EN] Forward-only goto is useful for breaking cleanly out of deeply nested loops or jumping to a shared cleanup label at the end of a function to free allocated memory and close file handles without duplicating cleanup code.

[HI] केवल आगे की ओर (Forward) goto का उपयोग गहरे नेस्टेड लूप्स से सीधे बाहर आने या फंक्शन के अंत में मेमोरी/फाइल क्लीनअप कोड को एक ही स्थान पर चलाने के लिए श्रेष्ठ माना जाता है।

Q3: How can you break out of two nested loops at once without using break twice?

दो बार break लिखे बिना दो नेस्टेड लूप्स से एक साथ बाहर कैसे निकल सकते हैं?

[EN] Either extract the nested loops into a helper function and exit via return, use a boolean flag checked in the outer loop condition, or use a clean forward goto exit_loops; statement.

[HI] नेस्टेड लूप्स को एक अलग फंक्शन में रखकर return का उपयोग करें, बाहरी लूप में एक फ्लैग वेरिएबल जांचें, या सीधे आगे की ओर goto exit_loops; लिखें।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)