--- id: cpp-do-while-loop title: "C++ Do/While Loop" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["do while", "at-least-once loop", "C++ do-while 반볡문"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.85 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "loops", "do-while"] raw_sources: ["https://www.w3schools.com/cpp/cpp_do_while_loop.asp"] applied_in: [] github_commit: "" --- # [[CPP Do/While Loop]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) This chapter explicitly flags something C's equivalent never called out as its own note: "the semicolon after the while condition is required!" β€” a small but real syntax trap, since `do {...} while(condition)` LOOKS like it should end like a regular `while` loop (no trailing semicolon), but the `do/while` FORM specifically requires one, unlike every other loop and conditional block in C++. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`do { ... } while (condition);`** β€” executes the block ONCE unconditionally, then checks the condition. [S1] - **Required trailing semicolon** β€” unlike `while(...) {...}` or `if(...) {...}`, the `do/while` form's closing `while(condition)` MUST end with a semicolon. [S1] - **Guaranteed first execution** β€” runs at least once even if the condition is false immediately. [S1] - **Input-validation pattern** β€” repeatedly prompting via `cin >>` until the loop condition fails. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Standard case with the required semicolon: `int i = 0; do { cout << i << "\n"; i++; } while (i < 5);`. [S1] - Guaranteed-once case (condition false at start): `int i = 10; do { cout << "i is " << i << "\n"; i++; } while (i < 5);` β€” still prints once. [S1] - Practical input-validation loop: `int number; do { cout << "Enter a positive number: "; cin >> number; } while (number > 0);`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **do/while λ’€μ—λŠ” λ°˜λ“œμ‹œ μ„Έλ―Έμ½œλ‘  ν•„μš”**: while(condition) 뒀에 μ„Έλ―Έμ½œλ‘ μ„ 빠뜨리기 μ‰¬μš΄ 문법적 함정이 μžˆλ‹€λŠ” 점이 C μ±•ν„°μ—λŠ” μ—†λ˜ 별도 μ£Όμ˜μ‚¬ν•­μœΌλ‘œ λͺ…μ‹œλ¨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) μ‚¬μš©μžλ‘œλΆ€ν„° μ–‘μˆ˜λ₯Ό μž…λ ₯λ°›λ˜ 0μ΄λ‚˜ μŒμˆ˜κ°€ μž…λ ₯될 λ•ŒκΉŒμ§€ λ°˜λ³΅ν•΄μ„œ λ¬Όμ–΄λ³΄λŠ” μž…λ ₯ 검증 루프가 μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) The required trailing semicolon after a do/while loop's condition (C++): ```cpp int i = 0; do { cout << i << "\n"; i++; } while (i < 5); // semicolon required here ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP While Loop RealLife]], [[CPP For Loop]], [[C Do While Loop]] - **μ°Έμ‘° λ§₯락:** while λ£¨ν”„μ˜ λ³€ν˜• β€” for 루프(For Loop) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Do/While Loop β€” https://www.w3schools.com/cpp/cpp_do_while_loop.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Do/While Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).