--- id: cpp-break title: "C++ Break and Continue" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["break statement", "continue statement", "loop control", "C++ break continue"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "loops", "break", "continue"] raw_sources: ["https://www.w3schools.com/cpp/cpp_break.asp"] applied_in: [] github_commit: "" --- # [[CPP Break and Continue]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The break-in-while example places `i++` BEFORE the `if (i == 4) break;` check, deliberately different ordering from the continue-in-while example (which places `i++` inside the `if` block before `continue`) β€” a subtle structural detail showing that where the increment sits relative to the break/continue check must be deliberately designed per-case to avoid either skipping a value or looping forever, unlike a `for` loop where the increment is guaranteed to run automatically regardless of `continue`. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`break`** β€” stops the loop COMPLETELY. [S1] - **`continue`** β€” skips the REST of the current iteration and jumps to the next one. [S1] - **Works in both `for` and `while` loops** β€” same semantics apply regardless of loop type. [S1] - **Increment placement matters in `while` loops** β€” unlike `for` loops (where the increment always runs), a `while` loop's increment must be manually placed correctly relative to `continue`, or the loop may infinite-loop or skip incorrectly. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - `break` stopping a for loop at i==4: `for (int i = 0; i < 10; i++) { if (i == 4) { break; } cout << i << "\n"; }` β€” prints 0,1,2,3 then stops entirely. [S1] - `continue` skipping just one value: `for (int i = 0; i < 10; i++) { if (i == 4) { continue; } cout << i << "\n"; }` β€” prints 0,1,2,3,5,6,7,8,9. [S1] - `break` in a while loop (increment BEFORE the break check): `int i = 0; while (i < 10) { cout << i << "\n"; i++; if (i == 4) { break; } }`. [S1] - `continue` in a while loop (increment INSIDE the if, before continue, to avoid an infinite loop): `int i = 0; while (i < 10) { if (i == 4) { i++; continue; } cout << i << "\n"; i++; }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **while λ£¨ν”„μ—μ„œλŠ” 증가식 μœ„μΉ˜λ₯Ό 직접 섀계해야 함**: for 루프와 달리 while λ£¨ν”„λŠ” 증가식(i++)이 μžλ™μœΌλ‘œ μ‹€ν–‰λ˜μ§€ μ•ŠμœΌλ―€λ‘œ, continueλ₯Ό μ“Έ λ•ŒλŠ” continue 이전에 λ°˜λ“œμ‹œ i++을 λ„£μ–΄μ•Ό λ¬΄ν•œλ£¨ν”„λ₯Ό ν”Όν•  수 μžˆλ‹€λŠ” 점이 두 예제(break용/continue용)의 μ„œλ‘œ λ‹€λ₯Έ i++ 배치둜 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” while λ£¨ν”„μ—μ„œ continueλ₯Ό μ“Έ λ•Œ 증가식을 continue 이전에 두어야 λ¬΄ν•œλ£¨ν”„λ₯Ό λ°©μ§€ν•œλ‹€λŠ” 점이 μ‹€μ „ λ””λ²„κΉ…μ—μ„œ ν”νžˆ λ†“μΉ˜λŠ” ν•¨μ •μœΌλ‘œ μ‹œμ‚¬λœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Placing the increment before continue in a while loop to avoid an infinite loop (C++): ```cpp int i = 0; while (i < 10) { if (i == 4) { i++; // must increment before continue continue; } cout << i << "\n"; i++; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.84 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP For Loop RealLife]], [[CPP Switch]], [[CPP Arrays]] - **μ°Έμ‘° λ§₯락:** 반볡문 μ„Ήμ…˜ λ§ˆμ§€λ§‰ β€” λ°°μ—΄(Arrays) μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Break and Continue β€” https://www.w3schools.com/cpp/cpp_break.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Break and Continue" page (Astra wiki-curation, P-Reinforce v3.1 format).