--- id: c-for-loop title: "C For Loop" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["for statement", "three-expression loop", "C for 반볡문"] 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", "for-loop"] raw_sources: ["https://www.w3schools.com/c/c_for_loop.php"] applied_in: [] github_commit: "" --- # [[C For Loop]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The source frames the `for` vs `while` choice as a matter of KNOWING the iteration count in advance β€” "when you know exactly how many times you want to loop... use the for loop instead of a while loop" β€” meaning `for` isn't a functionally different tool from `while` (a `for` loop can always be rewritten as a `while`), it's a structural convention that bundles initialization, condition, and increment into one line specifically for the fixed-count use case. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`for (expr1; expr2; expr3) { ... }`** β€” expr1 runs once before the loop starts; expr2 is the continuation condition checked each iteration; expr3 runs after each iteration's body. [S1] - **Fixed-count use case** β€” the recommended tool when the number of iterations is known ahead of time, unlike `while`'s open-ended condition-driven repetition. [S1] - **Flexible step expressions** β€” expr3 isn't limited to `++`; any increment/decrement/step size works (`i = i + 2`, `i--`, etc.). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic counting: `int i; for (i = 0; i < 5; i++) { printf("%d\n", i); }` β€” prints 0 to 4. [S1] - Custom step size for evens: `int i; for (i = 0; i <= 10; i = i + 2) { printf("%d\n", i); }`. [S1] - Accumulating a sum across iterations: `int sum = 0; int i; for (i = 1; i <= 5; i++) { sum = sum + i; } printf("Sum is %d", sum);`. [S1] - Countdown via decrement: `int i; for (i = 5; i > 0; i--) { printf("%d\n", i); }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - ν˜„μž¬κΉŒμ§€ 발견된 λͺ¨μˆœ 사항 μ—†μŒ (No contradictions found in available sources). ## πŸ› οΈ 적용 사둀 (Applied in summary) 1λΆ€ν„° 5κΉŒμ§€μ˜ 합을 for λ£¨ν”„λ‘œ λˆ„μ  κ³„μ‚°ν•˜λŠ” 예제(sum = sum + i)κ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Accumulating a running total across for-loop iterations (C): ```c int sum = 0; int i; for (i = 1; i <= 5; i++) { sum = sum + i; } printf("Sum is %d", sum); ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[C Do While Loop]], [[C For Loop Nested]], [[C For Loop RealLife]] - **μ°Έμ‘° λ§₯락:** for 루프 β€” 쀑첩 for 루프(For Loop Nested) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C For Loop β€” https://www.w3schools.com/c/c_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).