--- id: cpp-conditions-nested title: "C++ Nested If" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["if inside if", "dependent conditions", "C++ 쀑첩 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", "nested-if"] raw_sources: ["https://www.w3schools.com/cpp/cpp_conditions_nested.asp"] applied_in: [] github_commit: "" --- # [[CPP Nested If]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The same short-circuit benefit from C's Nested If chapter applies unchanged β€” the citizenship check (`isCitizen`) is never even evaluated if `age >= 18` is false, meaning nesting still functions as a genuine short-circuit optimization in C++, not just visual grouping of related checks. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Nested if** β€” placing an `if` inside another `if`'s block, so the inner condition is only checked when the outer condition already holds. [S1] - **Dependent condition modeling** β€” naturally expresses "check B only if A holds." [S1] - **Depth caution** β€” avoid nesting too deeply, as it hurts readability; often combined with `else`/`else if`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic two-level nesting: `int x = 15; int y = 25; if (x > 10) { cout << "x is greater than 10\n"; if (y > 20) { cout << "y is also greater than 20\n"; } }`. [S1] - Voting + citizenship real-life example: `int age = 20; bool isCitizen = true; if (age >= 18) { cout << "Old enough to vote.\n"; if (isCitizen) { cout << "And you are a citizen, so you can vote!\n"; } else { cout << "But you must be a citizen to vote.\n"; } } else { cout << "Not old enough to vote.\n"; }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - ν˜„μž¬κΉŒμ§€ 발견된 λͺ¨μˆœ 사항 μ—†μŒ (No contradictions found in available sources). C 챕터와 λ™μΌν•œ 쀑첩 if 및 단좕 평가 νŠΉμ„±μ΄ 확인됨. ## πŸ› οΈ 적용 사둀 (Applied in summary) νˆ¬ν‘œ κ°€λŠ₯ μ—°λ Ή(18μ„Έ 이상)을 λ¨Όμ € ν™•μΈν•˜κ³ , κ·Έ μ•ˆμ—μ„œλ§Œ μ‹œλ―ΌκΆŒ μ—¬λΆ€λ₯Ό μΆ”κ°€λ‘œ ν™•μΈν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) An inner condition (citizenship) checked only when the outer condition (age) already holds (C++): ```cpp int age = 20; bool isCitizen = true; if (age >= 18) { cout << "Old enough to vote.\n"; if (isCitizen) { cout << "And you are a citizen, so you can vote!\n"; } else { cout << "But you must be a citizen to vote.\n"; } } else { cout << "Not old enough to vote.\n"; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.83 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Conditions Logical]], [[CPP Conditions RealLife]], [[C Conditions Nested]] - **μ°Έμ‘° λ§₯락:** 쀑첩 if β€” 쑰건문 μ‹€μ „ 예제(Conditions RealLife) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Nested If β€” https://www.w3schools.com/cpp/cpp_conditions_nested.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Nested If" page (Astra wiki-curation, P-Reinforce v3.1 format).