--- id: csharp-while-loop title: "C# While Loop" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["do while loop C#", "C# while ๋ฐ˜๋ณต๋ฌธ"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.83 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "loops", "while"] raw_sources: ["https://www.w3schools.com/cs/cs_while_loop.php"] applied_in: [] github_commit: "" --- # [[CSharp While Loop]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) Both loop syntaxes on this page (`while (condition) {...}` and `do {...} while (condition);`) are identical to C/C++, and the source combines them into ONE chapter rather than splitting them across two โ€” a structural choice that differs from Topic_CPP, where While Loop and Do While Loop were separate documents โ€” meaning this single C# doc intentionally covers both variants together, matching the source page's own organization instead of forcing a 1:1 split that the source doesn't have. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`while (condition) { ... }`** โ€” repeats the block as long as `condition` stays `True`; the condition is checked BEFORE each iteration, so the body may run zero times. [S1] - **`do { ... } while (condition);`** โ€” the do/while variant; the block runs ONCE FIRST, then the condition is checked โ€” meaning the body always executes at least once, even if the condition is false from the start. [S1] - **Manual increment required** โ€” both loops require the loop variable to be manually advanced inside the body (`i++`); forgetting this creates an infinite loop, a warning the tutorial repeats for both variants. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - While example: `int i = 0; while (i < 5) { Console.WriteLine(i); i++; }` โ†’ prints 0,1,2,3,4. [S1] - Do/while example: `int i = 0; do { Console.WriteLine(i); i++; } while (i < 5);` โ†’ identical output to the while version in this case, but the guarantee differs (body always runs at least once). [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **while/do-while์ด C/C++์™€ ์™„์ „ํžˆ ๋™์ผํ•œ ๋ฌธ๋ฒ•ยท์˜๋ฏธ**: ์กฐ๊ฑด ์„ ๊ฒ€์‚ฌ(while) vs ํ›„๊ฒ€์‚ฌ(do-while) ๊ตฌ์กฐ์™€ ๋ฌธ๋ฒ•์ด C/C++์™€ ์ฐจ์ด๊ฐ€ ์—†๋‹ค๋Š” ์ ์ด ํ™•์ธ๋จ. [S1] - **์›๋ฌธ ๊ตฌ์กฐ์ƒ while๊ณผ do-while์ด ํ•œ ์ฑ•ํ„ฐ๋กœ ๋ฌถ์—ฌ ์žˆ์Œ**: Topic_CPP์—์„œ๋Š” While Loop์™€ Do While Loop๊ฐ€ ๋ณ„๋„ ๋ฌธ์„œ์˜€์ง€๋งŒ, C# ์‚ฌ์ด๋“œ๋ฐ”๋Š” ์ด ๋‘˜์„ cs_while_loop.php ํ•˜๋‚˜์˜ ํŽ˜์ด์ง€๋กœ ๋ฌถ์–ด ์ œ๊ณตํ•œ๋‹ค๋Š” ์ ์ด ํ™•์ธ๋จ โ€” ์†Œ์Šค ์‚ฌ์ดํŠธ์˜ ์‹ค์ œ ์ฑ•ํ„ฐ ๊ตฌ์„ฑ์„ ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผ ์ด ๋ฌธ์„œ๋„ ๋‘ ๋ณ€ํ˜•์„ ํ•จ๊ป˜ ๋‹ค๋ฃธ(1:1 ๋งคํ•‘ ์›์น™์„ ์†Œ์Šค์˜ ์‹ค์ œ ์ฑ•ํ„ฐ ๋‹จ์œ„์— ๋งž์ถค). [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) 0๋ถ€ํ„ฐ 4๊นŒ์ง€ ์ถœ๋ ฅํ•˜๋Š” ๋™์ผํ•œ ๋กœ์ง์„ while๊ณผ do/while ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ๊ฐ๊ฐ ๊ตฌํ˜„ํ•˜๋Š” ์˜ˆ์ œ๊ฐ€ ์›๋ฌธ์—์„œ ๋‚˜๋ž€ํžˆ ์ œ์‹œ๋จ. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) while (pre-check) vs. do/while (post-check, runs at least once) (C#): ```csharp int i = 0; while (i < 5) { Console.WriteLine(i); i++; } int j = 0; do { Console.WriteLine(j); j++; } while (j < 5); ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.83 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C# Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CSharp Switch]], [[CSharp For Loop]], [[CPP While Loop]], [[CPP Do While Loop]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** Loops ์„น์…˜ โ€” For Loop ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C# While Loop โ€” https://www.w3schools.com/cs/cs_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).