--- id: cpp-conditions title: "C++ If ... Else" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["if statement", "lowercase if", "C++ 쑰건문"] 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: ["cpp", "programming-language", "w3schools", "conditions", "if-statement"] raw_sources: ["https://www.w3schools.com/cpp/cpp_conditions.asp"] applied_in: [] github_commit: "" --- # [[CPP If ... Else]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Every rule from C's `if` chapter carries over verbatim β€” lowercase-only `if` (uppercase `If`/`IF` errors), the same six comparison operators, and the same bool-variable-for-readability pattern β€” meaning C++'s conditional syntax is a direct, unmodified continuation of C's, with the only visible difference being `cout <<` replacing `printf()` inside the branches. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Six comparison conditions** β€” `<`, `<=`, `>`, `>=`, `==`, `!=`, identical to C. [S1] - **Four conditional constructs** β€” `if`, `else`, `else if`, `switch` β€” same set as C. [S1] - **Case-sensitive keyword** β€” `if` must be lowercase; `If`/`IF` produce an error. [S1] - **Boolean-variable readability pattern** β€” storing a comparison's result in a `bool` variable before using it in `if` improves readability for complex/reused conditions. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic if with variables: `int x = 20; int y = 18; if (x > y) { cout << "x is greater than y"; }`. [S1] - Using a boolean variable to hold the condition: `bool isGreater = x > y; if (isGreater) { cout << "x is greater than y"; }`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - ν˜„μž¬κΉŒμ§€ 발견된 λͺ¨μˆœ 사항 μ—†μŒ (No contradictions found in available sources). C 챕터와 λ™μΌν•œ κ·œμΉ™μž„μ΄ 확인됨. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” λ³΅μž‘ν•˜κ±°λ‚˜ μž¬μ‚¬μš©λ˜λŠ” 쑰건을 bool λ³€μˆ˜μ— 미리 λ‹΄μ•„λ‘λŠ” νŒ¨ν„΄μ΄ 가독성 μžˆλŠ” 쑰건문 μž‘μ„±μ˜ μ‹€μ „ 관행이닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Storing a condition in a readable boolean variable before using it in an if statement (C++): ```cpp int x = 20; int y = 18; bool isGreater = x > y; if (isGreater) { cout << "x is greater than y"; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.85 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Booleans RealLife]], [[CPP Conditions Else]], [[C Conditions]] - **μ°Έμ‘° λ§₯락:** 쑰건문 μ„Ήμ…˜ 첫 챕터 β€” else λ¬Έ(Conditions Else) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ If ... Else β€” https://www.w3schools.com/cpp/cpp_conditions.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ If ... Else" page (Astra wiki-curation, P-Reinforce v3.1 format).