---
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).
