--- id: c-conditions-elseif title: "C Else If" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["else if chain", "top to bottom evaluation", "C else if ๋ฌธ"] 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: ["c", "programming-language", "w3schools", "conditions", "else-if"] raw_sources: ["https://www.w3schools.com/c/c_conditions_elseif.php"] applied_in: [] github_commit: "" --- # [[C Else If]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) Conditions in an if/else-if chain are checked strictly top-to-bottom and STOP at the first true match โ€” the source's time example explicitly notes "as soon as one condition is true, its block of code runs, and the rest are skipped," meaning even if a later condition would ALSO be true, only the FIRST matching branch ever executes; chain ORDER therefore determines behavior, not just correctness of each individual condition. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`else if`** โ€” tests a new condition only if the preceding condition(s) were false; can be chained multiple times. [S1] - **First-match-wins evaluation** โ€” conditions are checked top to bottom; the FIRST true condition's block runs and all subsequent conditions in the chain are skipped, even if they'd also evaluate true. [S1] - **Boolean-variable chaining** โ€” each condition in the chain can be pre-computed into a descriptively-named bool (`isMorning`, `isDay`) for readability. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Time-of-day chain: `int time = 16; if (time < 12) { printf("Good morning."); } else if (time < 18) { printf("Good day."); } else { printf("Good evening."); } // Outputs "Good day."` โ€” the first condition (`time < 12`) is false, the second (`time < 18`) is true, so only "Good day." prints. [S1] - Same chain with named booleans: `bool isMorning = time < 12; bool isDay = time < 18; if (isMorning) {...} else if (isDay) {...} else {...}`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **์ฒซ ๋ฒˆ์งธ๋กœ ์ฐธ์ธ ์กฐ๊ฑด๋งŒ ์‹คํ–‰๋จ**: ์ฒด์ธ ๋‚ด ์—ฌ๋Ÿฌ ์กฐ๊ฑด์ด ์ด๋ก ์ƒ ๋™์‹œ์— ์ฐธ์ผ ์ˆ˜ ์žˆ์–ด๋„, ์œ„์—์„œ๋ถ€ํ„ฐ ๋จผ์ € ์ฐธ์œผ๋กœ ํŒ์ •๋œ ์กฐ๊ฑด์˜ ๋ธ”๋ก๋งŒ ์‹คํ–‰๋˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ๊ฑด๋„ˆ๋›ด๋‹ค๋Š” ์ ์ด ๋ช…์‹œ์ ์œผ๋กœ ๊ฐ•์กฐ๋จ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” ์‹œ๊ฐ„๋Œ€์— ๋”ฐ๋ผ ์•„์นจ/๋‚ฎ/์ €๋… ์ธ์‚ฌ๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์ด else if ์ฒด์ธ์˜ ๋Œ€ํ‘œ์ ์ธ ์‹ค์ „ ํ™œ์šฉ ์˜ˆ์‹œ๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Chained else-if conditions evaluated top-to-bottom, stopping at the first match (C): ```c int time = 16; if (time < 12) { printf("Good morning."); } else if (time < 18) { printf("Good day."); } else { printf("Good evening."); } // Outputs "Good day." ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.85 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[C Conditions Else]], [[C Conditions Short Hand]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** else if ์ฒด์ธ โ€” ์‚ผํ•ญ ์—ฐ์‚ฐ์ž(Conditions Short Hand) ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C Else If โ€” https://www.w3schools.com/c/c_conditions_elseif.php ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C Else If" page (Astra wiki-curation, P-Reinforce v3.1 format).