---
id: csharp-while-loop
title: "C# While Loop"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["do while loop C#", "C# while 반복문"]
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", "while"]
raw_sources: ["https://www.w3schools.com/cs/cs_while_loop.php"]
applied_in: []
github_commit: ""
---

# [[CSharp While Loop]]

## 🎯 한 줄 통찰 (One-line insight)
Both loop syntaxes on this page (`while (condition) {...}` and `do {...} while (condition);`) are identical to C/C++, and the source combines them into ONE chapter rather than splitting them across two — a structural choice that differs from Topic_CPP, where While Loop and Do While Loop were separate documents — meaning this single C# doc intentionally covers both variants together, matching the source page's own organization instead of forcing a 1:1 split that the source doesn't have. [S1]

## 🧠 핵심 개념 (Core concepts)
- **`while (condition) { ... }`** — repeats the block as long as `condition` stays `True`; the condition is checked BEFORE each iteration, so the body may run zero times. [S1]
- **`do { ... } while (condition);`** — the do/while variant; the block runs ONCE FIRST, then the condition is checked — meaning the body always executes at least once, even if the condition is false from the start. [S1]
- **Manual increment required** — both loops require the loop variable to be manually advanced inside the body (`i++`); forgetting this creates an infinite loop, a warning the tutorial repeats for both variants. [S1]

## 📖 세부 내용 (Details)
- While example: `int i = 0; while (i < 5) { Console.WriteLine(i); i++; }` → prints 0,1,2,3,4. [S1]
- Do/while example: `int i = 0; do { Console.WriteLine(i); i++; } while (i < 5);` → identical output to the while version in this case, but the guarantee differs (body always runs at least once). [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **while/do-while이 C/C++와 완전히 동일한 문법·의미**: 조건 선검사(while) vs 후검사(do-while) 구조와 문법이 C/C++와 차이가 없다는 점이 확인됨. [S1]
- **원문 구조상 while과 do-while이 한 챕터로 묶여 있음**: Topic_CPP에서는 While Loop와 Do While Loop가 별도 문서였지만, C# 사이드바는 이 둘을 cs_while_loop.php 하나의 페이지로 묶어 제공한다는 점이 확인됨 — 소스 사이트의 실제 챕터 구성을 그대로 따라 이 문서도 두 변형을 함께 다룸(1:1 매핑 원칙을 소스의 실제 챕터 단위에 맞춤). [S1]

## 🛠️ 적용 사례 (Applied in summary)
0부터 4까지 출력하는 동일한 로직을 while과 do/while 두 가지 방식으로 각각 구현하는 예제가 원문에서 나란히 제시됨. [S1]

## 💻 코드 패턴 (Code patterns)
while (pre-check) vs. do/while (post-check, runs at least once) (C#):
```csharp
int i = 0;
while (i < 5)
{
    Console.WriteLine(i);
    i++;
}

int j = 0;
do
{
    Console.WriteLine(j);
    j++;
}
while (j < 5);
```

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

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

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

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