---
id: c-for-loop-nested
title: "C Nested Loops"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["inner outer loop", "multiplication table", "C 중첩 반복문"]
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", "loops", "nested-loops"]
raw_sources: ["https://www.w3schools.com/c/c_for_loop_nested.php"]
applied_in: []
github_commit: ""
---

# [[C Nested Loops]]

## 🎯 한 줄 통찰 (One-line insight)
The inner loop's total execution count MULTIPLIES with the outer loop's — the source explicitly annotates a 2-iteration outer loop paired with a 3-iteration inner loop as running the inner body "6 times (2 * 3)," not 2+3=5 — meaning nested loop cost grows multiplicatively, not additively, which is directly why nested loops are the natural fit for 2D structures like tables and matrices where total cells = rows × columns. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Nested loop** — a loop placed entirely inside another loop's body; the inner loop runs to completion once for EVERY single iteration of the outer loop. [S1]
- **Multiplicative execution count** — total inner-body executions = (outer iterations) × (inner iterations per outer iteration), not their sum. [S1]
- **Natural fit for 2D data** — tables, matrices, and multi-dimensional structures map naturally onto outer-loop-as-rows, inner-loop-as-columns. [S1]

## 📖 세부 내용 (Details)
- Basic nesting with explicit iteration-count annotation: `for (i = 1; i <= 2; ++i) { printf("Outer: %d\n", i); for (j = 1; j <= 3; ++j) { printf(" Inner: %d\n", j); } }` — outer runs 2 times, inner runs 6 times total (2×3). [S1]
- Multiplication table via nested loops: `for (i = 1; i <= 3; i++) { for (j = 1; j <= 3; j++) { printf("%d ", i * j); } printf("\n"); }` — produces a 3×3 grid: `1 2 3 / 2 4 6 / 3 6 9`. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **중첩 루프의 실행 횟수는 곱셈**: 바깥 루프 2회 × 안쪽 루프 3회 = 안쪽 코드 총 6회 실행이라는 점이 원문에서 직접 명시되어, 덧셈이 아닌 곱셈 관계임이 확인됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
3x3 구구단표를 중첩 for 루프로 출력하는 예제가 원문에서 직접 실전 활용 사례로 제시되며, 표/행렬 같은 2차원 데이터 구조에 중첩 루프가 자연스럽게 맞는다는 점이 강조됨. [S1]

## 💻 코드 패턴 (Code patterns)
A multiplication table built from two nested for loops (C):
```c
int i, j;
for (i = 1; i <= 3; i++) {
  for (j = 1; j <= 3; j++) {
    printf("%d ", i * j);
  }
  printf("\n");
}
// 1 2 3
// 2 4 6
// 3 6 9
```

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.85
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C Tutorial]]
- **관련 개념:** [[C For Loop]], [[C For Loop RealLife]], [[C Arrays Multi]]
- **참조 맥락:** 중첩 for 루프 — for 루프 실전 예제(For Loop RealLife) 챕터로 이어짐, 다차원 배열(Arrays Multi) 챕터와 연결.

## 📚 출처 (Sources)
- [S1] W3Schools — C Nested Loops — https://www.w3schools.com/c/c_for_loop_nested.php

## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C Nested Loops" page (Astra wiki-curation, P-Reinforce v3.1 format).
