---
id: csharp-for-loop
title: "C# For Loop"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["nested loops C#", "C# for 반복문"]
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: ["csharp", "programming-language", "w3schools", "loops", "for"]
raw_sources: ["https://www.w3schools.com/cs/cs_for_loop.php"]
applied_in: []
github_commit: ""
---

# [[CSharp For Loop]]

## 🎯 한 줄 통찰 (One-line insight)
The three-statement `for (statement1; statement2; statement3)` structure and its nested-loop composition (outer loop's body containing a complete inner loop, with the inner loop restarting fully on every single outer iteration) are unchanged from C/C++ — the nested-loop iteration-count math shown here (`2 outer × 3 inner = 6 inner executions total`) is the same multiplicative relationship this wiki has already confirmed for C and C++ nested loops. [S1]

## 🧠 핵심 개념 (Core concepts)
- **`for (statement1; statement2; statement3) { ... }`** — statement1 runs ONCE before the loop starts (initialization); statement2 is the condition checked before EVERY iteration; statement3 runs AFTER each iteration (typically increment/decrement). [S1]
- **Step size is arbitrary** — statement3 doesn't have to be `i++`; it can be any expression, e.g. `i = i + 2` to iterate only even numbers. [S1]
- **Nested loops** — a complete `for` loop placed inside another `for` loop's body; the inner loop runs to completion once for EVERY iteration of the outer loop. [S1]

## 📖 세부 내용 (Details)
- Basic count: `for (int i = 0; i < 5; i++) { Console.WriteLine(i); }` → prints 0 through 4. [S1]
- Step-by-2: `for (int i = 0; i <= 10; i = i + 2) { Console.WriteLine(i); }` → prints even numbers 0 through 10. [S1]
- Nested loop with execution counts explicitly annotated: 
  ```
  for (int i = 1; i <= 2; ++i) {
      Console.WriteLine("Outer: " + i);      // executes 2 times
      for (int j = 1; j <= 3; j++) {
          Console.WriteLine(" Inner: " + j); // executes 6 times total (2 * 3)
      }
  }
  ```
  [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **for문 구조와 중첩 반복 곱셈 관계가 C/C++와 동일**: 3-statement for 구조, 그리고 중첩 루프에서 "외부 루프 횟수 × 내부 루프 횟수"라는 곱셈 관계가 C/C++에서 확인된 것과 차이가 없다는 점이 이번 챕터에서 재확인됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
0-4 카운트, 짝수만 출력하는 step-2 루프, 2×3 중첩 루프의 실행 횟수를 주석으로 명시한 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

## 💻 코드 패턴 (Code patterns)
Nested for loops — inner runs fully for each outer iteration (C#):
```csharp
for (int i = 1; i <= 2; ++i)
{
    Console.WriteLine("Outer: " + i);       // 2 times
    for (int j = 1; j <= 3; j++)
    {
        Console.WriteLine(" Inner: " + j);  // 6 times total (2 * 3)
    }
}
```

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

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C# Tutorial]]
- **관련 개념:** [[CSharp While Loop]], [[CSharp Foreach Loop]], [[CPP For Loop Nested]]
- **참조 맥락:** Loops 섹션 — Foreach Loop 챕터로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — C# For Loop — https://www.w3schools.com/cs/cs_for_loop.php

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