--- id: csharp-conditions-elseif title: "C# The else if Statement" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["else if statement C#", "C# else if ๋ฌธ"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.82 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "conditions", "elseif"] raw_sources: ["https://www.w3schools.com/cs/cs_conditions_elseif.php"] applied_in: [] github_commit: "" --- # [[CSharp Conditions ElseIf]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) `else if` is not a distinct keyword in C# any more than in C/C++/Java โ€” it's just an `else` block whose body happens to be another `if` statement, which the three-way morning/day/evening example makes visible: each additional `else if` is really nested inside the previous `else`, and the chain only terminates in a plain `else` when every prior condition has failed, evaluated strictly top-to-bottom with short-circuit stopping at the first true condition. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`else if`** โ€” tests a NEW condition only when all prior conditions in the chain were false. [S1] - **Syntax**: `if (condition1) {...} else if (condition2) {...} else {...}` โ€” any number of `else if` blocks can be chained between the initial `if` and the final `else`. [S1] - **Top-to-bottom, first-match evaluation** โ€” conditions are checked in order; the first one that's true runs its block and the rest of the chain is skipped entirely. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Three-branch time-of-day example: `int time = 22; if (time < 10) { Console.WriteLine("Good morning."); } else if (time < 20) { Console.WriteLine("Good day."); } else { Console.WriteLine("Good evening."); }` โ€” since `22` is not `< 10` (condition1 false) and not `< 20` (condition2 also false), execution falls through to the final `else`, printing `"Good evening."`. [S1] - The tutorial notes that if `time` were `14` instead, the program would print `"Good day."` (condition2 would be true). [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **else if๋Š” ๋ณ„๋„ ํ‚ค์›Œ๋“œ๊ฐ€ ์•„๋‹ˆ๋ผ else์˜ ๋ณธ๋ฌธ์ด if์ธ ๊ตฌ์กฐ**: C/C++/Java์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ C#์˜ else if ์ฒด์ธ๋„ ์‹ค์ œ๋กœ๋Š” else ๋ธ”๋ก ์•ˆ์— ๋˜ ๋‹ค๋ฅธ if๊ฐ€ ์ค‘์ฒฉ๋œ ๊ตฌ์กฐ๋ผ๋Š” ์ ์ด ์‚ผ๋‹จ๊ณ„ ์‹œ๊ฐ„๋Œ€ ์˜ˆ์ œ(morning/day/evening)๋กœ ๋‹ค์‹œ ํ™•์ธ๋จ โ€” ๋ฌธ๋ฒ•์  ํŠน์ˆ˜ ์ผ€์ด์Šค๊ฐ€ ์•„๋‹ˆ๋ผ else+if์˜ ์ž์—ฐ์Šค๋Ÿฌ์šด ์กฐํ•ฉ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ์•„์นจ/๋‚ฎ/์ €๋… ์ธ์‚ฌ๋ง์„ ์‹œ๊ฐ„(time) ๊ฐ’์— ๋”ฐ๋ผ ์„ธ ๊ฐ€์ง€๋กœ ๋ถ„๊ธฐํ•˜๋Š” ์˜ˆ์ œ๊ฐ€ ์›๋ฌธ์—์„œ ์ง์ ‘ ์‹ค์ „ ํ™œ์šฉ ์‚ฌ๋ก€๋กœ ์ œ์‹œ๋จ. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Chained else-if โ€” first true condition wins, rest skipped (C#): ```csharp int time = 22; if (time < 10) { Console.WriteLine("Good morning."); } else if (time < 20) { Console.WriteLine("Good day."); } else { Console.WriteLine("Good evening."); } // Outputs "Good evening." ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.82 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C# Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CSharp Conditions Else]], [[CSharp Conditions Shorthand]], [[CSharp Switch]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** Conditions ์„น์…˜ โ€” Short Hand If...Else ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C# The else if Statement โ€” https://www.w3schools.com/cs/cs_conditions_elseif.php ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# The else if Statement" page (Astra wiki-curation, P-Reinforce v3.1 format).