--- id: c-while-loop title: "C While Loop" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["while statement", "zero-iteration loop", "C while 반볡문"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["c", "programming-language", "w3schools", "loops", "while"] raw_sources: ["https://www.w3schools.com/c/c_while_loop.php"] applied_in: [] github_commit: "" --- # [[C While Loop]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) A `while` loop can run ZERO times β€” if its condition is already false the very first time it's checked (e.g. `int i = 10; while (i < 5) {...}`), the body never executes at all, not even once β€” a behavior the source explicitly contrasts against the upcoming do/while chapter, which guarantees at least one execution regardless of the initial condition. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`while (condition) { ... }`** β€” repeats the block as long as the condition remains true, checked BEFORE each iteration (including the first). [S1] - **Zero-iteration possibility** β€” if the condition is false from the start, the loop body never runs at all. [S1] - **Mandatory condition-variable update** β€” forgetting to change the loop-controlling variable inside the body (e.g. omitting `i++`) causes an infinite loop. [S1] - **`i` as a counter convention** β€” the source explains `i` is traditionally used because it's short and stands for "index"/"iterator," not an arbitrary choice. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic counting loop: `int i = 0; while (i < 5) { printf("%d\n", i); i++; }`. [S1] - Countdown loop: `int countdown = 3; while (countdown > 0) { printf("%d\n", countdown); countdown--; } printf("Happy New Year!!\n");`. [S1] - Zero-iteration case: `int i = 10; while (i < 5) { printf("This will never be printed\n"); i++; }` β€” body never executes since the condition is false immediately. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **쑰건이 μ²˜μŒλΆ€ν„° 거짓이면 while λ£¨ν”„λŠ” ν•œ λ²ˆλ„ μ‹€ν–‰ μ•ˆ 됨**: do/while 루프(λ‹€μŒ 챕터)와 달리 일반 while λ£¨ν”„λŠ” μ‹œμž‘λΆ€ν„° 쑰건이 거짓이면 본문이 단 ν•œ λ²ˆλ„ μ‹€ν–‰λ˜μ§€ μ•ŠλŠ”λ‹€λŠ” 점이 λͺ…μ‹œμ μœΌλ‘œ λŒ€λΉ„λ¨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) μΉ΄μš΄νŠΈλ‹€μš΄ ν›„ "Happy New Year!!"λ₯Ό 좜λ ₯ν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) A while loop that never executes because its condition is false from the start (C): ```c int i = 10; while (i < 5) { printf("This will never be printed\n"); i++; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[C Switch]], [[C While Loop RealLife]], [[C Do While Loop]] - **μ°Έμ‘° λ§₯락:** 반볡문 μ„Ήμ…˜ 첫 챕터 β€” while 루프 μ‹€μ „ 예제(While Loop RealLife) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C While Loop β€” https://www.w3schools.com/c/c_while_loop.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C While Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).