--- id: cpp-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.83 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "conditions", "else-if"] raw_sources: ["https://www.w3schools.com/cpp/cpp_conditions_elseif.asp"] applied_in: [] github_commit: "" --- # [[CPP Else If]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) The first-match-wins rule (conditions checked top-to-bottom, stopping at the first true match, even if a later condition would also hold) is stated with the exact same wording and the exact same time-of-day example as C's chapter โ€” reconfirming that C++'s `else if` chain evaluation semantics are inherited from C without modification. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`else if`** โ€” tests a new condition only if the preceding condition(s) were false. [S1] - **First-match-wins evaluation** โ€” conditions checked top to bottom; the first true condition's block runs, remaining conditions are skipped. [S1] - **Boolean-variable chaining** โ€” each condition in the chain can be pre-computed into a descriptively-named bool. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Time-of-day chain: `int time = 16; if (time < 12) { cout << "Good morning."; } else if (time < 18) { cout << "Good day."; } else { cout << "Good evening."; } // Outputs "Good day."`. [S1] - Same chain with named booleans: `bool isMorning = time < 12; bool isDay = time < 18; if (isMorning) {...} else if (isDay) {...} else {...}`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - ํ˜„์žฌ๊นŒ์ง€ ๋ฐœ๊ฒฌ๋œ ๋ชจ์ˆœ ์‚ฌํ•ญ ์—†์Œ (No contradictions found in available sources). C ์ฑ•ํ„ฐ์™€ ์™„์ „ํžˆ ๋™์ผํ•œ ์šฐ์„  ๋งค์นญ ๊ทœ์น™์ž„์ด ํ™•์ธ๋จ. ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” ์‹œ๊ฐ„๋Œ€์— ๋”ฐ๋ผ ์•„์นจ/๋‚ฎ/์ €๋… ์ธ์‚ฌ๋ฅผ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์ด else if ์ฒด์ธ์˜ ๋Œ€ํ‘œ์ ์ธ ์‹ค์ „ ํ™œ์šฉ ์˜ˆ์‹œ๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Chained else-if conditions evaluated top-to-bottom, stopping at the first match (C++): ```cpp int time = 16; if (time < 12) { cout << "Good morning."; } else if (time < 18) { cout << "Good day."; } else { cout << "Good evening."; } // Outputs "Good day." ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.83 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C++ Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CPP Conditions Else]], [[CPP Conditions Shorthand]], [[C Conditions ElseIf]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** else if ์ฒด์ธ โ€” ์‚ผํ•ญ ์—ฐ์‚ฐ์ž(Conditions Shorthand) ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C++ Else If โ€” https://www.w3schools.com/cpp/cpp_conditions_elseif.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Else If" page (Astra wiki-curation, P-Reinforce v3.1 format).