--- id: csharp-break title: "C# Break and Continue" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["break continue C#", "C# break continue"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.82 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "loops", "break", "continue"] raw_sources: ["https://www.w3schools.com/cs/cs_break.php"] applied_in: [] github_commit: "" --- # [[CSharp Break]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) This chapter explicitly ties `break` back to the Switch chapter ("You have already seen the break statement used... to jump out of a switch statement"), making the point that `break` is ONE keyword with TWO distinct jump targets (switch block vs. loop) β€” while `continue` is entirely new here, skipping only the CURRENT iteration rather than exiting entirely; both keywords and their exact semantics are identical to C/C++, but the while-loop `continue` example reveals a subtle placement rule: the increment (`i++`) must happen BEFORE `continue` inside a `while` loop (unlike a `for` loop, where the increment happens automatically), or the loop would spin forever on the skipped value. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`break`** β€” already introduced for exiting a `switch` block; here reused to exit a LOOP entirely (for or while), stopping all further iterations immediately. [S1] - **`continue`** β€” skips the REST of the current iteration only, then proceeds to the next iteration; does not exit the loop. [S1] - **`for` loop placement** β€” both `break` and `continue` are placed inside a conditional check (`if (i == 4) { break; }` / `{ continue; }`) within the loop body. [S1] - **`while` loop placement subtlety** β€” in a `while` loop, `continue` must be preceded by the manual increment (`i++; continue;`), because `continue` jumps straight back to the condition check, skipping any code after it β€” including an increment that would otherwise appear later in the body. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - `break` in a `for` loop: `for (int i = 0; i < 10; i++) { if (i == 4) { break; } Console.WriteLine(i); }` β†’ prints 0,1,2,3 then stops entirely at 4. [S1] - `continue` in a `for` loop: `for (int i = 0; i < 10; i++) { if (i == 4) { continue; } Console.WriteLine(i); }` β†’ prints 0,1,2,3,5,6,7,8,9 (skips only 4). [S1] - `break` in a `while` loop: increment happens BEFORE the break check (`i++; if (i == 4) { break; }`). [S1] - `continue` in a `while` loop: increment happens BEFORE `continue` is called (`if (i == 4) { i++; continue; }`), specifically to avoid an infinite loop that would otherwise keep re-testing `i == 4` forever. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **breakκ°€ switch와 loop 두 κ³³μ—μ„œ μž¬μ‚¬μš©λ˜λŠ” 동일 ν‚€μ›Œλ“œμž„μ„ λͺ…μ‹œ**: 이번 μ±•ν„°λŠ” breakκ°€ switch μ±•ν„°μ—μ„œ 이미 배운 것과 같은 ν‚€μ›Œλ“œμ΄λ©°, 단지 νƒˆμΆœ λŒ€μƒμ΄ switch λΈ”λ‘μ—μ„œ λ£¨ν”„λ‘œ λ°”λ€” λΏμ΄λΌλŠ” 점을 직접 언급함 β€” C/C++와 λ§ˆμ°¬κ°€μ§€λ‘œ ν•˜λ‚˜μ˜ ν‚€μ›Œλ“œκ°€ λ¬Έλ§₯에 따라 λ‹€λ₯Έ 블둝을 νƒˆμΆœν•˜λŠ” 데 μž¬μ‚¬μš©λ¨. [S1] - **while λ£¨ν”„μ—μ„œ continue μ•žμ— 증감식이 λ°˜λ“œμ‹œ 와야 함**: for λ£¨ν”„λŠ” 증감(statement3)이 μžλ™μœΌλ‘œ μ‹€ν–‰λ˜μ§€λ§Œ, while λ£¨ν”„λŠ” continueκ°€ 쑰건 κ²€μ‚¬λ‘œ λ°”λ‘œ μ ν”„ν•˜λ―€λ‘œ continue보닀 λ¨Όμ € i++λ₯Ό 싀행해두지 μ•ŠμœΌλ©΄ λ¬΄ν•œ 루프가 λ°œμƒν•œλ‹€λŠ” 점이 while 루프 continue μ˜ˆμ œμ—μ„œ 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) i==4일 λ•Œ 루프λ₯Ό μ™„μ „νžˆ νƒˆμΆœ(break)ν•˜λŠ” μ˜ˆμ œμ™€, i==4만 κ±΄λ„ˆλ›°κ³  λ‚˜λ¨Έμ§€λŠ” 계속 좜λ ₯(continue)ν•˜λŠ” μ˜ˆμ œκ°€ for/while μ–‘μͺ½ λͺ¨λ‘μ—μ„œ 원문에 직접 μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) continue in a while loop β€” increment must come first to avoid infinite loop (C#): ```csharp int i = 0; while (i < 10) { if (i == 4) { i++; // must increment BEFORE continue continue; } Console.WriteLine(i); i++; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.82 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C# Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSharp Foreach Loop]], [[CSharp Switch]], [[CSharp Arrays]], [[CPP Break]] - **μ°Έμ‘° λ§₯락:** Loops μ„Ήμ…˜μ˜ λ§ˆμ§€λ§‰ 챕터 β€” Arrays μ„Ήμ…˜μœΌλ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C# Break and Continue β€” https://www.w3schools.com/cs/cs_break.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Break and Continue" page (Astra wiki-curation, P-Reinforce v3.1 format).