--- id: java-for-loop title: "Java For Loop" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["for loop", "자바 for 반복문"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "loops", "for"] raw_sources: ["https://www.w3schools.com/java/java_for_loop.asp"] applied_in: [] github_commit: "" --- # [[Java For Loop]] ## 🎯 한 줄 통찰 (One-line insight) Choose `for` over `while` specifically when the iteration count is known in advance — the tutorial frames this as the deciding factor between the two loop types, since a for loop bundles init/condition/increment into one line while while requires manual setup outside the loop. [S1] ## 🧠 핵심 개념 (Core concepts) - **`for (statement1; statement2; statement3) { ... }`** — statement1 runs once before the loop, statement2 is the continuation condition, statement3 runs after each iteration. [S1] - **When to use for vs while** — for loop is preferred when the exact iteration count is known ahead of time. [S1] - **False condition from the start** — like while, a for loop with a false initial condition skips the body entirely. [S1] ## 📖 세부 내용 (Details) - Print 0-4: `for (int i = 0; i < 5; i++) { System.out.println(i); }`. [S1] - Even numbers: `for (int i = 0; i <= 10; i = i + 2) { System.out.println(i); }`. [S1] - Sum 1-5: `int sum = 0; for (int i = 1; i <= 5; i++) { sum = sum + i; } System.out.println("Sum is " + sum);`. [S1] - Countdown: `for (int i = 5; i > 0; i--) { System.out.println(i); }`. [S1] - Never runs: `for (int i = 10; i < 5; i++) { System.out.println("This will never be printed"); }`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) 소스에서 모순되는 정보는 발견되지 않음. ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — 합계 계산, 카운트다운 등 반복 횟수를 미리 아는 상황의 표준 도구다. [S1] ## 💻 코드 패턴 (Code patterns) Sum accumulation with for loop (Java): ```java int sum = 0; for (int i = 1; i <= 5; i++) { sum = sum + i; } System.out.println("Sum is " + sum); ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.90 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[Java Tutorial]] - **관련 개념:** [[Java While Loop]], [[Java For Loop Nested]], [[Java For Each Loop]], [[Java For Loop Real Life]] - **참조 맥락:** 반복 횟수를 아는 경우의 표준 반복문 — 중첩/for-each로 확장됨. ## 📚 출처 (Sources) - [S1] W3Schools — Java For Loop — https://www.w3schools.com/java/java_for_loop.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java For Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).