Loops in Java: while and do-while Loop Syntax Notes in Hindi & English : while और do-while लूप्स: सिंटैक्स और निष्पादन नियम और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

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

Overview: Java's while and do-while loops provide indefinite iteration controlled by a boolean condition: 'while' tests the condition before entering the body (0 or more runs), whereas 'do-while' tests after executing the body (at least 1 run). Critical JLS rules distinguish the two loops, including the mandatory trailing semicolon on do-while, local variable scoping inside do { }, and compile-time unreachable statement detection on while(false).

अध्याय सार: जावा में while और do-while लूप्स boolean शर्त द्वारा नियंत्रित पुनरावृत्ति प्रदान करते हैं: 'while' बॉडी चलने से पहले शर्त जांचता है (0 या अधिक बार निष्पादन), जबकि 'do-while' बॉडी चलने के बाद शर्त जांचता है (कम से कम 1 बार निष्पादन)। do-while के अंत में अनिवार्य सेमीकोलन, ब्लॉक वेरिएबल स्कोप और while(false) पर कंपाइल-टाइम अनरीचेबल त्रुटि इन दोनों के प्रमुख परीक्षा नियम हैं।

Loops in Java: while and do-while Loop Syntax: Detailed Notes & Architecture (while और do-while लूप्स: सिंटैक्स और निष्पादन नियम)

1. while Loop: Entry-Controlled Execution Semantics (while लूप: एंट्री-कंट्रोल्ड निष्पादन नियम)

[EN] The 'while (condition) { body }' loop is an entry-controlled (pre-test) loop best suited when the exact number of iterations is unknown before execution begins (such as reading lines from a stream until EOF). Before each pass, the JVM evaluates the strictly boolean condition; if initially false, the body executes zero times and control skips straight past the loop. Unlike do-while, placing a semicolon directly after the header—'while (i < 5);'—creates an empty body loop (often causing an infinite hang if 'i' is updated only inside the detached block below). Per JLS §14.22, writing a compile-time constant 'while (false) { ... }' triggers an immediate compile-time 'unreachable statement' error because the body can never execute.

[HI] 'while (condition) { body }' एक एंट्री-कंट्रोल्ड (प्री-टेस्ट) लूप है जो तब उपयुक्त होता है जब पुनरावृत्ति की संख्या पहले से ज्ञात न हो। प्रत्येक चक्कर से पहले boolean शर्त जांची जाती है; यदि शर्त पहली बार में ही false हो, तो लूप बॉडी 0 बार चलती है। हेडर के तुरंत बाद गलती से सेमीकोलन ('while (i < 5);') लगाने पर खाली बॉडी वाला लूप बन जाता है जो अक्सर प्रोग्राम को अनंत लूप में फँसा देता है। JLS §14.22 के अनुसार कंपाइल-टाइम स्थिरांक 'while (false) { ... }' लिखने पर तुरंत 'unreachable statement' कंपाइल त्रुटि आती है।

2. do-while Loop: Exit-Controlled Execution and Mandatory Semicolon (do-while लूप: एग्जिट-कंट्रोल्ड निष्पादन और अनिवार्य सेमीकोलन)

[EN] The 'do { body } while (condition);' loop is an exit-controlled (post-test) loop that executes its body first and evaluates the boolean condition afterward. Because testing occurs at the bottom, the body is guaranteed to execute at least once even when the condition is already false on entry—making do-while ideal for interactive menus and prompt-until-valid input loops. Syntax requires a trailing semicolon ';' right after '(condition)'; omitting it causes a syntax error at compile time. Interestingly, unlike 'while (false)', writing 'do { ... } while (false);' compiles cleanly and executes the body once!

[HI] 'do { body } while (condition);' एक एग्जिट-कंट्रोल्ड (पोस्ट-टेस्ट) लूप है जो पहले बॉडी को चलाता है और बाद में boolean शर्त की जांच करता है। चूंकि शर्त अंत में जांची जाती है, इसलिए शर्त शुरू से false होने पर भी बॉडी कम से कम एक बार अवश्य चलती है—जो मेन्यू-संचालित प्रोग्राम और इनपुट सत्यापन के लिए आदर्श है। सिंटैक्स में '(condition);' के बाद अंत में सेमीकोलन ';' लगाना अनिवार्य है; इसे भूलने पर कंपाइल त्रुटि आती है। 'while (false)' के विपरीत, 'do { ... } while (false);' पूरी तरह वैध है और ठीक एक बार निष्पादित होता है।

3. Variable Scope, break, and continue Mechanics (वेरिएबल स्कोप, break और continue की कार्यप्रणाली)

[EN] Any local variable declared inside the body of a while or do-while loop exists only for a single iteration and cannot be accessed outside the braces. In particular, declaring 'do { int x = 5; } while (x < 10);' fails to compile because 'x' goes out of scope at the closing '}' before the trailing while(x < 10) condition is evaluated! The 'break;' statement immediately terminates the innermost enclosing loop and resumes execution right after the loop. The 'continue;' statement skips the remaining statements in the current iteration and jumps directly to re-evaluating the while or do-while condition (so ensure loop counters are updated before 'continue' to prevent infinite loops).

[HI] while या do-while बॉडी के भीतर घोषित कोई भी लोकल वेरिएबल केवल उसी पुनरावृत्ति तक सीमित रहता है। इसी कारण 'do { int x = 5; } while (x < 10);' कंपाइल नहीं होता क्योंकि शर्त वाले भाग से पहले ही '}' पर 'x' का स्कोप समाप्त हो जाता है। 'break;' कथन तुरंत लूप को समाप्त कर बाहर आ जाता है। 'continue;' वर्तमान पुनरावृत्ति के शेष कोड को छोड़कर सीधे लूप की शर्त की पुनः जांच पर ले जाता है (अतः अनंत लूप से बचने के लिए काउंटर अपडेट continue से पहले होना चाहिए)।

4. Infinite Loops and Unreachable Statement Analysis (अनंत लूप्स और अनरीचेबल स्टेटमेंट विश्लेषण)

[EN] Canonical infinite loops in Java are written as 'while (true) { ... }' (or 'for (;;)') and rely on an internal conditional 'break', 'return', or exception to exit. Because the Java compiler tracks reachability during compilation, placing any statement directly AFTER 'while (true) { ... }' that contains NO 'break' statement results in a compile-time 'unreachable statement' error. However, if the condition uses a non-final boolean variable such as 'boolean run = false; while (run) { ... }', javac treats it as a runtime variable rather than a compile-time constant, so no unreachable error is flagged. Note also a tricky syntax quirk: writing 'do while(cond);' without braces is invalid unless a valid single statement exists between 'do' and 'while' (like 'do i++; while (i < 3);').

[HI] जावा में अनंत लूप सामान्यतः 'while (true) { ... }' से बनाए जाते हैं जिन्हें भीतर 'break' या 'return' से रोका जाता है। कंपाइलर रीचेबिलिटी की जांच करता है: यदि 'while (true)' ब्लॉक में कोई 'break' न हो और उसके बाद कोई स्टेटमेंट लिखा जाए, तो कंपाइल-टाइम 'unreachable statement' त्रुटि आती है। परंतु यदि शर्त में 'boolean run = false; while (run)' जैसा नॉन-final वेरिएबल हो, तो कंपाइलर कोई अनरीचेबल त्रुटि नहीं देता। 'do' और 'while' के बीच यदि कर्ली ब्रेसिज़ न हों, तो ठीक एक वैध कथन (जैसे 'do i++; while (i < 3);') होना आवश्यक है।

Syntax, Formula & Technical Example (Loops in Java: while and do-while Loop Syntax)

public class WhileDoWhileDemo {
    public static void main(String[] args) {
        int n = 3, choice = 0;
        while (n > 0) // Entry-controlled: checks condition first
            System.out.println("while n = " + n--);
        do {          // Exit-controlled: runs at least once
            System.out.println("do-while ran: choice = " + choice);
        } while (choice > 0); // Trailing semicolon is mandatory
    }
}

Loops in Java: while and do-while Loop Syntax Quick Reference & Comparison Table

Loop Characteristicwhile Loop BehaviorKey Exam Fact
Evaluation TimingEntry-controlled (checks condition before body)do-while is exit-controlled (checks condition after body)
Minimum Executions0 iterations if condition starts falsedo-while guarantees at least 1 execution
Trailing SemicolonNo semicolon after while(cond) headerdo { ... } while (cond); mandates a trailing semicolon
Compile-time falsewhile(false) fails with unreachable statement errordo { ... } while(false); compiles and runs once

Loops in Java: while and do-while Loop Syntax Top 20 Bilingual MCQs with Answers

Q1. How many times is the body of a do-while loop guaranteed to execute even if its condition is initially false?

(शर्त के शुरू से ही false होने पर भी do-while लूप की बॉडी कम से कम कितनी बार निष्पादित होती है?)

(A) Depends on the JVM implementation

(B) 0 times

(C) At least 1 time

(D) 2 times

Correct Answer: (C)

[EN] Because do-while is an exit-controlled loop, the body always executes once before the condition is evaluated at the bottom.

[HI] चूंकि do-while एक एग्जिट-कंट्रोल्ड लूप है, इसलिए शर्त की जांच अंत में होती है और बॉडी कम से कम 1 बार अवश्य चलती है।

Q2. Which semicolon rule strictly differentiates 'do-while' from 'while' syntax in Java?

(जावा में कौन सा सेमीकोलन नियम 'do-while' और 'while' के सिंटैक्स को स्पष्ट रूप से अलग करता है?)

(A) while (cond); { ... } requires a mandatory semicolon after (cond)

(B) Neither allows a semicolon after (cond)

(C) Both require semicolons at the end of closing braces

(D) do { ... } while (cond); requires a mandatory semicolon after (cond)

Correct Answer: (D)

[EN] Java syntax mandates a semicolon terminating 'do { ... } while (cond);', whereas putting ';' after 'while (cond);' turns the body into an empty statement.

[HI] जावा सिंटैक्स में 'do { ... } while (cond);' के अंत में सेमीकोलन अनिवार्य है, जबकि सामान्य 'while (cond)' के बाद सेमीकोलन लगाने से खाली लूप बन जाता है।

Q3. What happens when you compile: while (false) { System.out.println("Hi"); }

(while (false) { System.out.println("Hi"); } को कंपाइल करने पर क्या होता है?)

(A) Compiles cleanly and prints nothing

(B) Compile-time error: unreachable statement

(C) Prints Hi once

(D) Throws IllegalStateException at runtime

Correct Answer: (B)

[EN] Under JLS §14.22, javac rejects 'while (false)' because the loop body is provably unreachable at compile time.

[HI] JLS §14.22 के अनुसार 'while (false)' की बॉडी कभी नहीं चल सकती, इसलिए javac 'unreachable statement' कंपाइल त्रुटि देता है।

Q4. What happens when you compile and run: do { System.out.println("Once"); } while (false);

(do { System.out.println("Once"); } while (false); को कंपाइल और रन करने पर क्या होता है?)

(A) Compiles cleanly and prints "Once"

(B) Enters an infinite loop

(C) Prints nothing

(D) Compile-time error: unreachable statement

Correct Answer: (A)

[EN] In 'do { ... } while (false);', the body executes once before testing 'false', so the body IS reachable and valid.

[HI] do-while में बॉडी 'false' की जांच से पहले एक बार निष्पादित होती है, इसलिए यह वैध है और "Once" प्रिंट करता है।

Q5. What happens when you compile: do { int x = 1; x++; } while (x < 5);

(do { int x = 1; x++; } while (x < 5); को कंपाइल करने पर क्या होगा?)

(A) Loops 4 times and stops

(B) Compile-time error: cannot find symbol 'x' inside while (x < 5)

(C) Infinite loop

(D) Prints 5

Correct Answer: (B)

[EN] Variables declared inside the do { } block go out of scope at the closing brace '}' before the while(x < 5) condition is checked.

[HI] do { } ब्लॉक के भीतर घोषित वेरिएबल '}' पर समाप्त हो जाता है, इसलिए बाहर while(x < 5) में 'x' पहचान में नहीं आता।

Q6. What is the output of: int i = 1; while (i < 5); { System.out.print(i); i++; }

(int i = 1; while (i < 5); { System.out.print(i); i++; } चलाने पर क्या होगा?)

(A) Compile-time syntax error

(B) Prints 5

(C) Runs forever as an infinite loop without printing anything

(D) Prints 1234

Correct Answer: (C)

[EN] The semicolon right after while(i < 5) acts as an empty loop body. Since i stays 1 forever (< 5), the loop never reaches the print block.

[HI] while(i < 5) के तुरंत बाद लगा सेमीकोलन खाली बॉडी बन जाता है; i हमेशा 1 रहने से लूप अनंत काल तक चलता है और कुछ प्रिंट नहीं होता।

Q7. What is the output of: int i = 0; while (i < 3) { i++; if (i == 2) continue; System.out.print(i); }

(int i = 0; while (i < 3) { i++; if (i == 2) continue; System.out.print(i); } का आउटपुट क्या होगा?)

(A) 13

(B) 123

(C) Infinite loop printing 1

(D) 1

Correct Answer: (A)

[EN] Pass 1: i=1, prints 1. Pass 2: i=2, continue skips printing 2. Pass 3: i=3, prints 3. Loop terminates when i < 3 is false -> output "13".

[HI] चक्कर 1: i=1 (1 प्रिंट)। चक्कर 2: i=2 (continue से प्रिंट छूटता है)। चक्कर 3: i=3 (3 प्रिंट)। अतः आउटपुट "13" आता है।

Q8. What happens if you place 'System.out.println("Done");' right after 'while (true) { System.out.println("Loop"); }' (with no break)?

(बिना break वाले 'while (true) { System.out.println("Loop"); }' के ठीक बाद 'System.out.println("Done");' लिखने पर क्या होगा?)

(A) Compile-time error: unreachable statement on the "Done" line

(B) Throws StackOverflowError

(C) Prints Done once before Loop

(D) Compiles cleanly and prints Loop forever

Correct Answer: (A)

[EN] Because while(true) lacks any break/return exit path, the compiler proves the statement after the loop can never be reached.

[HI] चूंकि while(true) में बाहर निकलने का कोई break/return नहीं है, इसलिए कंपाइलर लूप के बाद की पंक्ति को 'unreachable statement' त्रुटि देता है।

Q9. What is the output of: int x = 5; do { System.out.print(x); x--; } while (x > 5);

(int x = 5; do { System.out.print(x); x--; } while (x > 5); का आउटपुट क्या होगा?)

(A) Infinite loop

(B) Nothing

(C) 54

(D) 5

Correct Answer: (D)

[EN] do-while executes the body first: prints 5, decrements x to 4, then tests (4 > 5) which is false, exiting with output "5".

[HI] do-while पहले 5 प्रिंट करता है और x को 4 घटाता है; फिर शर्त (4 > 5) false मिलने पर बाहर आ जाता है, अतः "5" प्रिंट होता है।

Q10. What happens if you write: boolean flag = false; while (flag) { System.out.println("Test"); }

(boolean flag = false; while (flag) { System.out.println("Test"); } लिखने पर क्या होगा?)

(A) Infinite loop

(B) Prints Test once

(C) Compiles cleanly and prints nothing at runtime

(D) Compile-time error: unreachable statement

Correct Answer: (C)

[EN] Unlike 'while(false)', 'flag' is a non-final variable rather than a compile-time constant, so javac allows compilation and skips the body at runtime.

[HI] 'while(false)' के विपरीत, यहाँ 'flag' एक नॉन-final वेरिएबल है, इसलिए कंपाइलर कोई त्रुटि नहीं देता और रनटाइम पर 0 बार लूप चलता है।

Q11. What is the output of: int count = 0; while (count++ < 3) { System.out.print(count); }

(int count = 0; while (count++ < 3) { System.out.print(count); } का आउटपुट क्या होगा?)

(A) 012

(B) 12

(C) 123

(D) 0123

Correct Answer: (C)

[EN] Check 0 < 3 (true, count becomes 1 -> prints 1); check 1 < 3 (true -> prints 2); check 2 < 3 (true -> prints 3); check 3 < 3 (false, stops).

[HI] 0 < 3 पर count बढ़कर 1 प्रिंट होता है, 1 < 3 पर 2 प्रिंट होता है, 2 < 3 पर 3 प्रिंट होता है और 3 < 3 असत्य होने पर रुक जाता है (आउटपुट 123)।

Q12. What happens with: int i = 0; while (i < 3) { if (i == 1) continue; System.out.print(i); i++; }

(int i = 0; while (i < 3) { if (i == 1) continue; System.out.print(i); i++; } का परिणाम क्या होगा?)

(A) Prints 012

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

(C) Prints 02

(D) Compile-time error

Correct Answer: (B)

[EN] At i=0, prints 0 and i becomes 1. At i=1, 'continue' jumps straight back to while(i < 3) skipping 'i++', keeping i stuck at 1 forever!

[HI] i=0 पर 0 प्रिंट होकर i=1 होता है। i=1 पर 'continue' नीचे मौजूद 'i++' को छोड़ देता है, जिससे i हमेशा 1 अटका रहकर अनंत लूप बना देता है।

Q13. Does 'do System.out.print("Hi"); while (false);' (without curly braces) compile in Java?

(क्या बिना कर्ली ब्रेसिज़ के 'do System.out.print("Hi"); while (false);' जावा में कंपाइल होता है?)

(A) No, do-while strictly requires curly braces even for one statement

(B) Compiles only if a break is included

(C) Yes, because the body contains a single valid statement

(D) No, because while(false) is unreachable

Correct Answer: (C)

[EN] Curly braces in do-while are optional when the body is a single statement (though braces are strongly recommended for clarity).

[HI] यदि लूप बॉडी में केवल एक स्टेटमेंट हो, तो while और do-while दोनों में कर्ली ब्रेसिज़ वैकल्पिक होते हैं।

Q14. Which Java loop construct is best suited for displaying a console menu at least once and repeating until the user enters '0'?

(कंसोल मेन्यू को कम से कम एक बार दिखाने और यूज़र द्वारा '0' दबाने तक दोहराने के लिए कौन सा जावा लूप सबसे उपयुक्त है?)

(A) while loop

(B) switch statement alone

(C) enhanced for-each loop

(D) do-while loop

Correct Answer: (D)

[EN] A menu must always be presented at least once before checking the user's exit choice, matching the exit-controlled do-while pattern.

[HI] मेन्यू को यूज़र के विकल्प की जांच से पहले कम से कम एक बार दिखाना आवश्यक होता है, जिसके लिए एग्जिट-कंट्रोल्ड do-while लूप सर्वोत्तम है।

Q15. Inside a labeled outer while loop 'outer: while(cond1) { while(cond2) { break outer; } }', what does 'break outer;' do?

(लेबल किए गए बाहरी while लूप 'outer: while(cond1) { while(cond2) { break outer; } }' में 'break outer;' क्या करता है?)

(A) Exits only the inner loop

(B) Restarts the outer loop from cond1

(C) Causes a compile-time error because labels only work on for loops

(D) Immediately terminates both the inner loop and the labeled outer while loop

Correct Answer: (D)

[EN] A labeled break transfers control immediately out of the named enclosing statement—here exiting the entire outer while loop.

[HI] लेबल किया गया break उस नाम वाले बाहरी लूप सहित सभी आंतरिक लूपों को तुरंत समाप्त करके बाहर निकल आता है।

Q16. Which statement comparing while and do-while loops in Java is FALSE?

(जावा में while और do-while लूप्स की तुलना करने वाला निम्नलिखित में से कौन सा कथन असत्य है?)

(A) A break statement inside either loop exits only the innermost enclosing loop by default

(B) A while loop may execute 0 times, whereas a do-while executes at least 1 time

(C) A continue statement inside do-while jumps to testing the trailing while(condition)

(D) In both while and do-while, the loop condition must be an int or boolean expression

Correct Answer: (D)

[EN] Just like 'if', both while(...) and do ... while(...) strictly accept only boolean (or Boolean) conditions—never integers.

[HI] 'if' की तरह ही, while(...) और do ... while(...) दोनों में शर्त केवल boolean (या Boolean) होनी चाहिए, कभी पूर्णांक नहीं।

Q17. Within Loops in Java: while and do-while Loop Syntax, which loop characteristic directly maps to: "Entry-controlled (checks condition before body)"?

(Loops in Java: while and do-while Loop Syntax में कौन सा Loop Characteristic सीधे "Entry-controlled (checks condition before body)" से संबंधित है?)

(A) Compile-time false

(B) Minimum Executions

(C) Trailing Semicolon

(D) Evaluation Timing

Correct Answer: (D)

[EN] In Loops in Java: while and do-while Loop Syntax, 'Evaluation Timing' handles 'Entry-controlled (checks condition before body)' (do-while is exit-controlled (checks condition after body)).

[HI] Loops in Java: while and do-while Loop Syntax में 'Evaluation Timing' का कार्य/विवरण 'Entry-controlled (checks condition before body)' (do-while is exit-controlled (checks condition after body)) है।

Q18. Which option accurately describes 'Minimum Executions' in Loops in Java: while and do-while Loop Syntax?

(Loops in Java: while and do-while Loop Syntax के संदर्भ में 'Minimum Executions' की सही विशेषता कौन सी है?)

(A) No semicolon after while(cond) header

(B) while(false) fails with unreachable statement error

(C) 0 iterations if condition starts false

(D) Entry-controlled (checks condition before body)

Correct Answer: (C)

[EN] 'Minimum Executions' provides '0 iterations if condition starts false' — key point: do-while guarantees at least 1 execution.

[HI] 'Minimum Executions' का मुख्य विवरण '0 iterations if condition starts false' है (do-while guarantees at least 1 execution)।

Q19. In Loops in Java: while and do-while Loop Syntax, identify the correct parameter for the specification: "No semicolon after while(cond) header".

(Loops in Java: while and do-while Loop Syntax में "No semicolon after while(cond) header" विवरण किस विकल्प के लिए सही है?)

(A) Compile-time false

(B) Evaluation Timing

(C) Minimum Executions

(D) Trailing Semicolon

Correct Answer: (D)

[EN] 'Trailing Semicolon' corresponds to 'No semicolon after while(cond) header' (do { ... } while (cond); mandates a trailing semicolon).

[HI] 'Trailing Semicolon' का संबंध 'No semicolon after while(cond) header' (do { ... } while (cond); mandates a trailing semicolon) से है।

Q20. Considering Loops in Java: while and do-while Loop Syntax, what key behavior defines 'Compile-time false'?

(Loops in Java: while and do-while Loop Syntax में 'Compile-time false' की मुख्य भूमिका या मान क्या है?)

(A) while(false) fails with unreachable statement error

(B) No semicolon after while(cond) header

(C) 0 iterations if condition starts false

(D) Entry-controlled (checks condition before body)

Correct Answer: (A)

[EN] 'Compile-time false' represents 'while(false) fails with unreachable statement error' (do { ... } while(false); compiles and runs once).

[HI] 'Compile-time false' का अर्थ/मान 'while(false) fails with unreachable statement error' है (do { ... } while(false); compiles and runs once)।

Loops in Java: while and do-while Loop Syntax — Exam FAQs

Q1: Can every while loop be rewritten as a for loop, and vice versa?

क्या हर while लूप को for लूप में और हर for लूप को while लूप में बदला जा सकता है?

[EN] Yes; 'for (init; cond; update) { body }' is functionally equivalent to '{ init; while (cond) { body; update; } }' (except for how 'continue' jumps straight to 'update' in a for loop rather than skipping it).

[HI] हाँ; 'for (init; cond; update)' को while लूप के रूप में और 'while (cond)' को 'for (; cond; )' के रूप में लिखा जा सकता है (बस continue व्यवहार का ध्यान रखना होता है)।

Q2: Why is 'while (false)' a compile error in Java while 'if (false)' is allowed?

जावा में 'if (false)' की अनुमति है, जबकि 'while (false)' पर कंपाइल त्रुटि क्यों आती है?

[EN] The JLS intentionally allows 'if (false)' as an idiom for conditional compilation / feature flags without triggering unreachable code errors, whereas 'while (false)' serves no practical purpose and indicates a bug.

[HI] JLS में कंडीशनल संकलन/डीबगिंग फ़्लैग के लिए 'if (false)' को जानबूझकर छूट दी गई है, जबकि 'while (false)' का कोई व्यावहारिक उपयोग न होने से इसे अनरीचेबल एरर माना जाता है।

Q3: Does 'continue' inside a do-while loop re-run the loop body unconditionally or test the condition first?

क्या do-while लूप के भीतर 'continue' सीधे बॉडी को फिर चलाता है या पहले शर्त की जांच करता है?

[EN] When 'continue' executes inside a do-while loop, control jumps directly down to the trailing 'while (condition);' check. The next iteration runs ONLY if that condition evaluates to true.

[HI] do-while के भीतर 'continue' चलने पर नियंत्रण सीधे नीचे 'while (condition);' की जांच पर जाता है; अगला चक्कर तभी चलता है जब शर्त true हो।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)