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