Jump Statements in Java: break, continue and Labeled break Notes in Hindi & English : जंप स्टेटमेंट्स: break, continue और लेबल्ड (Labeled) break और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

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

Overview: Java jump statements—break, continue, and return—alter sequential control flow within loops, switch blocks, and methods. Labeled break and labeled continue provide structured control over nested loops without permitting unstructured goto jumps.

अध्याय सार: जावा के जंप स्टेटमेंट्स—break, continue और return—लूप्स, switch ब्लॉक्स और मेथड्स के भीतर क्रमिक नियंत्रण प्रवाह को बदलते हैं। लेबल्ड break और लेबल्ड continue अनियंत्रित goto जंप की अनुमति दिए बिना नेस्टेड लूप्स पर व्यवस्थित नियंत्रण प्रदान करते हैं।

Jump Statements in Java: break, continue and Labeled break: Detailed Notes & Architecture (जंप स्टेटमेंट्स: break, continue और लेबल्ड (Labeled) break)

1. Unlabeled break Statement in Loops and switch (लूप्स और switch में अनलेबल्ड break स्टेटमेंट)

[EN] An unlabeled break immediately terminates only the innermost enclosing loop (for, while, do-while) or switch statement. Control resumes directly at the first statement following that terminated construct. In a switch statement without break, execution falls through sequentially into subsequent case branches. Using an unlabeled break outside any loop or switch causes a compile-time error stating 'break outside switch or loop'.

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

2. Unlabeled continue Statement Behavior (अनलेबल्ड continue स्टेटमेंट का व्यवहार)

[EN] The continue statement skips all remaining statements in the current iteration of the innermost enclosing loop and starts the next iteration. In a for loop, continue transfers control directly to the update clause before re-evaluating the boolean condition. In while and do-while loops, continue jumps immediately to the boolean condition test; failing to update the loop counter beforehand causes an infinite loop. Unlike break, unlabeled continue cannot be used inside a standalone switch block.

[HI] continue स्टेटमेंट सबसे भीतरी लूप के वर्तमान इटरेशन के शेष सभी स्टेटमेंट्स को छोड़कर अगला इटरेशन शुरू कर देता है। for लूप में continue नियंत्रण को सीधे अपडेट क्लॉज़ पर भेजता है जिसके बाद बूलियन कंडीशन जांची जाती है। while और do-while लूप में continue सीधे कंडीशन जांच पर कूदता है; पहले काउंटर अपडेट न होने पर अनंत लूप बन सकता है। break के विपरीत, अनलेबल्ड continue का उपयोग अकेले switch ब्लॉक में नहीं किया जा सकता।

3. Labeled break and Labeled continue in Nested Loops (नेस्टेड लूप्स में लेबल्ड break और लेबल्ड continue)

[EN] A label is an identifier followed by a colon placed immediately before a statement or loop, such as outer: for(...). A labeled break exits the specified enclosing block or outer loop entirely, making it clean to escape multi-level nested searches. Notice that labeled break works on any enclosing labeled block (even an if block or standalone braces), whereas labeled continue must target an enclosing loop statement. Jumping to a label that does not enclose the break or continue statement fails compilation.

[HI] लेबल एक आइडेंटिफ़ायर होता है जिसके बाद कोलन लगाकर उसे किसी स्टेटमेंट या लूप के ठीक पहले लिखा जाता है, जैसे outer: for(...)। लेबल्ड break निर्दिष्ट बाहरी ब्लॉक या आउटर लूप से पूरी तरह बाहर निकल जाता है, जो मल्टी-लेवल नेस्टेड सर्च से निकलने के लिए उपयोगी है। ध्यान दें कि लेबल्ड break किसी भी संलग्न लेबल्ड ब्लॉक (यहाँ तक कि कोष्ठक ब्लॉक) पर काम करता है, जबकि लेबल्ड continue केवल संलग्न लूप को ही लक्षित कर सकता है। ऐसे लेबल पर जंप करना जो break या continue को घेरता न हो, कंपाइल नहीं होता।

4. Why goto is Reserved and Role of return (goto क्यों आरक्षित है और return की भूमिका)

[EN] Although goto is listed among Java's keywords alongside const, Java forbids its use and throws a compile-time syntax error if written. Language designers excluded goto to prevent spaghetti code and preserve verifiable bytecode stack frames, offering labeled break/continue instead. The return statement exits the entire enclosing method immediately, optionally passing a computed value back to the caller. Code placed sequentially after an unconditional break, continue, or return inside the same block causes an 'unreachable statement' compile error.

[HI] यद्यपि goto और const जावा के आरक्षित कीवर्ड्स में शामिल हैं, जावा में goto का उपयोग वर्जित है और लिखने पर कंपाइल-टाइम एरर आती है। डिज़ाइनरों ने स्पेगेटी कोड रोकने और सुरक्षित बाइटकोड स्टैक फ़्रेम बनाए रखने के लिए goto की जगह लेबल्ड break/continue दिए हैं। return स्टेटमेंट पूरे मेथड से तुरंत बाहर निकलता है और वैकल्पिक रूप से कॉलर को एक मान लौटाता है। एक ही ब्लॉक में बिना शर्त break, continue या return के ठीक बाद लिखा कोड 'unreachable statement' कंपाइल एरर देता है।

Syntax, Formula & Technical Example (Jump Statements in Java: break, continue and Labeled break)

outer:
for (int r = 1; r <= 3; r++) {
    for (int c = 1; c <= 3; c++) {
        if (c == 2) continue;
        if (r == 2 && c == 3) break outer;
        System.out.print(r + "-" + c + " ");
    }
}

Jump Statements in Java: break, continue and Labeled break Quick Reference & Comparison Table

Jump StatementTarget ScopeExam Trap / Rule
Unlabeled breakExits innermost loop or switch blockCauses fall-through bugs if omitted in switch
Unlabeled continueSkips to next cycle of innermost loopIllegal inside standalone switch; jumps to update in for
Labeled breakExits any enclosing labeled block or loopReplaces forward goto for exiting nested loops
Labeled continueAdvances enclosing labeled loop to next stepLabel must directly precede a loop construct

Jump Statements in Java: break, continue and Labeled break Top 20 Bilingual MCQs with Answers

Q1. Which keyword is reserved in Java as an unused keyword and cannot be used as a variable name or jump command?

(जावा में कौन-सा कीवर्ड अप्रयुक्त आरक्षित कीवर्ड है जिसे न वेरिएबल नाम और न ही जंप कमांड के रूप में उपयोग किया जा सकता है?)

(A) label

(B) exit

(C) jump

(D) goto

Correct Answer: (D)

[EN] Both goto and const are reserved unused keywords in Java; labeled break replaces structured jumps.

[HI] जावा में goto और const दोनों अप्रयुक्त आरक्षित कीवर्ड हैं; लेबल्ड break व्यवस्थित जंप का विकल्प देता है।

Q2. In a for(int i = 0; i < 5; i++) loop, where does continue transfer control immediately?

(for(int i = 0; i < 5; i++) लूप में continue नियंत्रण को तुरंत कहाँ स्थानांतरित करता है?)

(A) To the first statement outside the loop

(B) To the update expression i++

(C) To the initialization int i = 0

(D) To the garbage collector

Correct Answer: (B)

[EN] Inside a for loop, continue executes the update expression i++ before re-evaluating the condition i < 5.

[HI] for लूप में continue कंडीशन i < 5 की पुनः जांच करने से पहले अपडेट एक्सप्रेशन i++ को निष्पादित करता है।

Q3. What will this code print? for(int i=1; i<=5; i++) { if(i==3) continue; if(i==5) break; System.out.print(i); }

(यह कोड क्या प्रिंट करेगा? for(int i=1; i<=5; i++) { if(i==3) continue; if(i==5) break; System.out.print(i); })

(A) 12

(B) 1234

(C) 124

(D) 1245

Correct Answer: (C)

[EN] Iteration 3 is skipped by continue, and iteration 5 terminates the loop before printing, leaving 1, 2, and 4.

[HI] इटरेशन 3 continue से छूट जाता है और 5 पर प्रिंट से पहले break हो जाता है, इसलिए 124 प्रिंट होता है।

Q4. Which statement causes a compile-time error when placed directly inside a switch case without an enclosing loop?

(बिना किसी बाहरी लूप के सीधे switch केस के भीतर रखे जाने पर कौन-सा स्टेटमेंट कंपाइल-टाइम एरर देता है?)

(A) Unlabeled break

(B) Unlabeled continue

(C) throw

(D) return

Correct Answer: (B)

[EN] continue applies only to loops, so using continue inside a standalone switch without an enclosing loop fails compilation.

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

Q5. What happens if you place a statement immediately after an unconditional break inside the same code block?

(एक ही कोड ब्लॉक में बिना शर्त break के ठीक बाद कोई स्टेटमेंट लिखने पर क्या होता है?)

(A) The statement executes once after the loop

(B) Compiler silently ignores the statement

(C) Runtime DeadCodeException

(D) Compile-time error: unreachable statement

Correct Answer: (D)

[EN] javac strictly rejects unreachable code following unconditional break, continue, return, or throw.

[HI] javac बिना शर्त break, continue, return या throw के बाद आने वाले कोड को 'unreachable statement' एरर से अस्वीकार करता है।

Q6. Which target construct is valid for a labeled break but INVALID for a labeled continue?

(कौन-सा लक्ष्य निर्माण लेबल्ड break के लिए वैध है लेकिन लेबल्ड continue के लिए अमान्य है?)

(A) A labeled for loop

(B) A labeled do-while loop

(C) A labeled while loop

(D) A labeled standalone code block { ... } or if block

Correct Answer: (D)

[EN] Labeled break can exit any enclosing labeled block, whereas labeled continue must target a loop statement.

[HI] लेबल्ड break किसी भी संलग्न लेबल्ड ब्लॉक से बाहर निकल सकता है, जबकि लेबल्ड continue के लिए लक्ष्य का लूप होना आवश्यक है।

Q7. What is the output of: outer: for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { if(j==1) break outer; System.out.print(i+""+j); } }

(कोड outer: for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { if(j==1) break outer; System.out.print(i+""+j); } } का आउटपुट क्या है?)

(A) 00011011

(B) 001020

(C) 0010

(D) 00

Correct Answer: (D)

[EN] At i=0, j=0 it prints 00; when j=1, break outer exits both the inner and outer loops immediately.

[HI] i=0, j=0 पर 00 प्रिंट होता है; j=1 होते ही break outer दोनों लूप्स से तुरंत बाहर निकल जाता है।

Q8. What happens in a while loop if continue executes before the loop counter increment statement?

(while लूप में लूप काउंटर इंक्रीमेंट स्टेटमेंट से पहले continue चलने पर क्या होता है?)

(A) JVM automatically increments the counter

(B) It risks creating an infinite loop because the counter stays unchanged

(C) Throws InfiniteLoopError

(D) The loop terminates immediately

Correct Answer: (B)

[EN] In while loops, continue jumps straight to the condition test, skipping any update written later in the body.

[HI] while लूप में continue सीधे कंडीशन जांच पर कूदता है, जिससे बॉडी में बाद में लिखा अपडेट छूट जाता है और अनंत लूप बन सकता है।

Q9. What is the output when running: int i = 0; while (i < 4) { i++; if (i == 2) continue; System.out.print(i); }

(कोड int i = 0; while (i < 4) { i++; if (i == 2) continue; System.out.print(i); } चलाने पर क्या आउटपुट मिलेगा?)

(A) 1234

(B) 13

(C) 013

(D) 134

Correct Answer: (D)

[EN] i increments before the check: 1 prints, 2 is skipped by continue, 3 and 4 print, then i < 4 becomes false.

[HI] जांच से पहले i बढ़ता है: 1 प्रिंट होता है, 2 continue से छूट जाता है, 3 और 4 प्रिंट होते हैं।

Q10. What error occurs if a method writes: loopA: System.out.println("Hi"); break loopA; ?

(यदि कोई मेथड loopA: System.out.println("Hi"); break loopA; लिखे तो क्या त्रुटि होगी?)

(A) Runs cleanly and skips nothing

(B) Compile-time error: undefined label loopA

(C) Prints Hi infinitely

(D) Runtime JumpException

Correct Answer: (B)

[EN] break loopA must be lexically inside the labeled statement; here loopA ends at the semicolon before break.

[HI] break loopA का उस लेबल्ड स्टेटमेंट के भीतर होना अनिवार्य है; यहाँ लेबल सेमीकोलन पर ही समाप्त हो जाता है।

Q11. Which jump statement exits the current method completely and returns control to its caller?

(कौन-सा जंप स्टेटमेंट वर्तमान मेथड से पूरी तरह बाहर निकलकर नियंत्रण कॉलर को लौटाता है?)

(A) break

(B) System.exit

(C) continue

(D) return

Correct Answer: (D)

[EN] return terminates the active method call frame and returns control (and optional value) to the caller.

[HI] return सक्रिय मेथड कॉल को समाप्त करता है और नियंत्रण (तथा वैकल्पिक मान) कॉलर को लौटाता है।

Q12. What happens if break is omitted inside a switch case block?

(switch case ब्लॉक के अंदर break छोड़ देने पर क्या होता है?)

(A) Compiler inserts break automatically

(B) Switch exits after matching one case

(C) Throws MissingBreakException

(D) Execution falls through into the next case statements until a break or end of switch

Correct Answer: (D)

[EN] Traditional switch blocks exhibit fall-through behavior unless terminated by break, return, or throw.

[HI] पारंपरिक switch ब्लॉक में break, return या throw न होने पर निष्पादन अगले case में फॉल-थ्रू कर जाता है।

Q13. What will this snippet output? outer: for(int i=1; i<=2; i++) { for(int j=1; j<=2; j++) { if(j==2) continue outer; System.out.print(i+j); } }

(यह कोड क्या आउटपुट देगा? outer: for(int i=1; i<=2; i++) { for(int j=1; j<=2; j++) { if(j==2) continue outer; System.out.print(i+j); } })

(A) 23

(B) 2334

(C) 2

(D) 24

Correct Answer: (A)

[EN] For i=1, j=1 prints 2, then j=2 triggers continue outer advancing i to 2; j=1 prints 3, then j=2 exits outer.

[HI] i=1, j=1 पर 2 प्रिंट होता है फिर j=2 पर continue outer i को 2 कर देता है; i=2, j=1 पर 3 प्रिंट होता है।

Q14. Which of the following is NOT true about labeled jump statements in Java?

(जावा में लेबल्ड जंप स्टेटमेंट्स के बारे में निम्न में से कौन-सा कथन सत्य नहीं है?)

(A) Labeled continue requires the labeled target to be a loop

(B) Labels follow standard Java identifier rules followed by a colon

(C) Labeled break exits the entire enclosing labeled block

(D) Labeled break can jump forward to any label located later in the method

Correct Answer: (D)

[EN] Java only allows jumping out of an enclosing labeled construct, never arbitrarily forward or into another block.

[HI] जावा केवल संलग्न लेबल्ड संरचना से बाहर निकलने की अनुमति देता है, किसी आगे के लेबल या अन्य ब्लॉक में कूदने की नहीं।

Q15. Can System.out.println("Hello"); exist legally inside a labeled block like block1: { if(true) break block1; System.out.println("Skipped"); }?

(क्या block1: { if(true) break block1; System.out.println("Skipped"); } कंपाइल और रन हो सकता है?)

(A) Yes, and it prints Skipped

(B) Yes, because break block1 is inside an if condition, so javac considers the print reachable

(C) No, blocks cannot carry labels

(D) No, javac flags Skipped as unreachable

Correct Answer: (B)

[EN] Conditional if(true) does not trigger unreachable-statement rejection in javac, and break block1 skips printing at runtime.

[HI] if(true) के भीतर break होने पर javac अगले स्टेटमेंट को unreachable नहीं मानता और रनटाइम पर प्रिंट स्किप हो जाता है।

Q16. What happens if you declare a loop label with the same name as a local variable in the same method?

(क्या एक ही मेथड में लोकल वेरिएबल के समान नाम वाला लूप लेबल घोषित किया जा सकता है?)

(A) Runtime LinkageError

(B) Compile-time duplicate identifier error

(C) It is legal because labels and variables occupy separate namespaces in Java

(D) Label overwrites the local variable

Correct Answer: (C)

[EN] Java maintains distinct namespaces for labels, variables, types, and methods, so identical names do not clash.

[HI] जावा में लेबल्स, वेरिएबल्स, टाइप्स और मेथड्स के नेमस्पेस अलग-अलग होते हैं, इसलिए समान नाम से टकराव नहीं होता।

Q17. Within Jump Statements in Java: break, continue and Labeled break, which jump statement directly maps to: "Exits innermost loop or switch block"?

(Jump Statements in Java: break, continue and Labeled break में कौन सा Jump Statement सीधे "Exits innermost loop or switch block" से संबंधित है?)

(A) Unlabeled continue

(B) Unlabeled break

(C) Labeled break

(D) Labeled continue

Correct Answer: (B)

[EN] In Jump Statements in Java: break, continue and Labeled break, 'Unlabeled break' handles 'Exits innermost loop or switch block' (Causes fall-through bugs if omitted in switch).

[HI] Jump Statements in Java: break, continue and Labeled break में 'Unlabeled break' का कार्य/विवरण 'Exits innermost loop or switch block' (Causes fall-through bugs if omitted in switch) है।

Q18. Which option accurately describes 'Unlabeled continue' in Jump Statements in Java: break, continue and Labeled break?

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

(A) Exits innermost loop or switch block

(B) Advances enclosing labeled loop to next step

(C) Skips to next cycle of innermost loop

(D) Exits any enclosing labeled block or loop

Correct Answer: (C)

[EN] 'Unlabeled continue' provides 'Skips to next cycle of innermost loop' — key point: Illegal inside standalone switch; jumps to update in for.

[HI] 'Unlabeled continue' का मुख्य विवरण 'Skips to next cycle of innermost loop' है (Illegal inside standalone switch; jumps to update in for)।

Q19. In Jump Statements in Java: break, continue and Labeled break, identify the correct parameter for the specification: "Exits any enclosing labeled block or loop".

(Jump Statements in Java: break, continue and Labeled break में "Exits any enclosing labeled block or loop" विवरण किस विकल्प के लिए सही है?)

(A) Unlabeled continue

(B) Unlabeled break

(C) Labeled continue

(D) Labeled break

Correct Answer: (D)

[EN] 'Labeled break' corresponds to 'Exits any enclosing labeled block or loop' (Replaces forward goto for exiting nested loops).

[HI] 'Labeled break' का संबंध 'Exits any enclosing labeled block or loop' (Replaces forward goto for exiting nested loops) से है।

Q20. Considering Jump Statements in Java: break, continue and Labeled break, what key behavior defines 'Labeled continue'?

(Jump Statements in Java: break, continue and Labeled break में 'Labeled continue' की मुख्य भूमिका या मान क्या है?)

(A) Skips to next cycle of innermost loop

(B) Exits innermost loop or switch block

(C) Exits any enclosing labeled block or loop

(D) Advances enclosing labeled loop to next step

Correct Answer: (D)

[EN] 'Labeled continue' represents 'Advances enclosing labeled loop to next step' (Label must directly precede a loop construct).

[HI] 'Labeled continue' का अर्थ/मान 'Advances enclosing labeled loop to next step' है (Label must directly precede a loop construct)।

Jump Statements in Java: break, continue and Labeled break — Exam FAQs

Q1: Why did Java disallow the goto keyword while keeping it reserved?

जावा ने goto कीवर्ड को आरक्षित रखते हुए भी इसके उपयोग पर रोक क्यों लगाई?

[EN] Reserving goto prevents developers from using it as an identifier while forbidding arbitrary jumps that break structured programming and complicate bytecode verification.

[HI] goto को आरक्षित रखने से इसे आइडेंटिफ़ायर बनने से रोका जाता है, जबकि अनियंत्रित जंप वर्जित रहने से संरचित प्रोग्रामिंग और बाइटकोड वेरिफिकेशन सुरक्षित रहता है।

Q2: What is the difference between break and System.exit(0)?

break और System.exit(0) में क्या अंतर है?

[EN] break exits only the enclosing loop or switch statement while keeping the program running; System.exit(0) terminates the entire running Java Virtual Machine immediately.

[HI] break केवल संलग्न लूप या switch से बाहर निकलता है जबकि प्रोग्राम चलता रहता है; System.exit(0) पूरे JVM को तुरंत बंद कर देता है।

Q3: Does labeled continue work with switch statements?

क्या लेबल्ड continue का उपयोग switch स्टेटमेंट के साथ किया जा सकता है?

[EN] Only if the label belongs to an enclosing loop outside the switch; you cannot put a label directly on switch and target it with continue.

[HI] केवल तभी जब लेबल switch के बाहर किसी संलग्न लूप का हो; आप सीधे switch पर लेबल लगाकर continue नहीं कर सकते।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)