--- id: c-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.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["c", "programming-language", "w3schools", "conditions", "nested-if"] raw_sources: ["https://www.w3schools.com/c/c_conditions_nested.php"] applied_in: [] github_commit: "" --- # [[C Nested If]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) A nested `if` only ever gets EVALUATED at all if the outer condition is true β€” the voting-and-citizenship example never even checks `isCitizen` if `age >= 18` is false, meaning nesting isn't just visual grouping of related checks, it's a genuine short-circuit optimization where the inner condition's cost (and its own true/false branches) is entirely skipped when the outer gate fails. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Nested if** β€” placing an `if` statement inside another `if`'s block, so the inner condition is only checked when the outer condition is already true. [S1] - **Dependent condition modeling** β€” naturally expresses "check B only if A holds" logic, like age eligibility gating a citizenship check. [S1] - **Depth caution** β€” the source explicitly warns against nesting too deeply, as it can hurt readability; nested if is commonly combined with `else`/`else if` for richer decision trees. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic two-level nesting: `int x = 15; int y = 25; if (x > 10) { printf("x is greater than 10\n"); if (y > 20) { printf("y is also greater than 20\n"); } }` β€” both print since both conditions hold. [S1] - Voting + citizenship real-life example: `int age = 20; bool isCitizen = true; if (age >= 18) { printf("Old enough to vote.\n"); if (isCitizen) { printf("And you are a citizen, so you can vote!\n"); } else { printf("But you must be a citizen to vote.\n"); } } else { printf("Not old enough to vote.\n"); }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **쀑첩 if의 단좕 평가 효과**: λ°”κΉ₯ 쑰건이 거짓이면 μ•ˆμͺ½ if의 쑰건 μžμ²΄κ°€ μ•„μ˜ˆ ν‰κ°€λ˜μ§€ μ•ŠλŠ”λ‹€λŠ” 점이 λ‚˜μ΄/μ‹œλ―ΌκΆŒ 예제둜 확인됨 β€” κ΄€λ ¨ μ—†λŠ” ν•˜μœ„ 쑰건을 λΆˆν•„μš”ν•˜κ²Œ κ²€μ‚¬ν•˜μ§€ μ•ŠλŠ” νš¨μœ¨μ„±μ„ 제곡. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) νˆ¬ν‘œ κ°€λŠ₯ μ—°λ Ή(18μ„Έ 이상)을 λ¨Όμ € ν™•μΈν•˜κ³ , κ·Έ μ•ˆμ—μ„œλ§Œ μ‹œλ―ΌκΆŒ μ—¬λΆ€λ₯Ό μΆ”κ°€λ‘œ ν™•μΈν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) An inner condition (citizenship) checked only when the outer condition (age) already holds (C): ```c int age = 20; bool isCitizen = true; if (age >= 18) { printf("Old enough to vote.\n"); if (isCitizen) { printf("And you are a citizen, so you can vote!\n"); } else { printf("But you must be a citizen to vote.\n"); } } else { printf("Not old enough to vote.\n"); } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.84 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[C Conditions Logical]], [[C Conditions RealLife]] - **μ°Έμ‘° λ§₯락:** 쀑첩 if β€” 쑰건문 μ‹€μ „ 예제(Conditions RealLife) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C Nested If β€” https://www.w3schools.com/c/c_conditions_nested.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C Nested If" page (Astra wiki-curation, P-Reinforce v3.1 format).