🟡 Control Flow · Lesson 15
if, else-if and else Statements
if, else-if and else Statements
What is if, else-if and else Statements?
if, else-if and else Statements
Conditional statements allow a program to make decisions. They execute different blocks of code depending on whether a condition is true or false.
Conditional statements allow a program to make decisions. They execute different blocks of code depending on whether a condition is true or false.
Level
🟡 Control Flow and Core Programming
🟡 Control Flow and Core Programming
Example File
if-else.cppMain Focus
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
Why should you learn this?
- It helps you write correct and readable C++ programs.
- It is used repeatedly in school practicals, projects and competitive programming.
- It builds the base for advanced topics such as OOP, STL and data structures.
Important Terms
| Term | Meaning / Use |
|---|---|
| condition | if, else-if and else Statements programming में Condition use होता है। |
| if | if, else-if and else Statements programming में If use होता है। |
| else if | if, else-if and else Statements programming में Else if use होता है। |
| else | if, else-if and else Statements programming में Else use होता है। |
| block | if, else-if and else Statements programming में Block use होता है। |
Syntax / Pattern
C++
if (condition) { } else { }Example Program
main.cpp
#include <iostream>
using namespace std;
int main(){
int marks = 72;
if (marks >= 90) cout << "A+";
else if (marks >= 60) cout << "Pass";
else cout << "Need Improvement";
return 0;
}Expected Output
Pass
Program Explanation
- First condition is false, second is true.
- Only the matching block is executed.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.
Where will you use it?
- grade systems
- eligibility checks
- login validation
Common Mistakes
- Using = instead of ==.
- Missing braces in multi-line blocks.
Practice Tasks
- Check pass/fail from marks.
- Find greatest of three numbers.
Summary
if, else-if and else Statements एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
if, else-if and else Statements क्या है?
if, else-if and else Statements
Conditional statements allow a program to make decisions. They execute different blocks of code depending on whether a condition is true or false.
Conditional statements allow a program to make decisions. They execute different blocks of code depending on whether a condition is true or false.
Level
🟡 Control Flow and Core Programming
🟡 Control Flow and Core Programming
Example File
if-else.cppमुख्य फोकस
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
इसे क्यों सीखें?
- यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
- यह school practicals, projects और competitive programming में बार-बार use होता है।
- यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।
ज़रूरी Terms
| Term | अर्थ / उपयोग |
|---|---|
| condition | Condition if, else-if and else Statements programming में use होता है। |
| if | If if, else-if and else Statements programming में use होता है। |
| else if | Else if if, else-if and else Statements programming में use होता है। |
| else | Else if, else-if and else Statements programming में use होता है। |
| block | Block if, else-if and else Statements programming में use होता है। |
Syntax / Pattern
C++
if (condition) { } else { }Example Program
main.cpp
#include <iostream>
using namespace std;
int main(){
int marks = 72;
if (marks >= 90) cout << "A+";
else if (marks >= 60) cout << "Pass";
else cout << "Need Improvement";
return 0;
}Expected Output
Pass
Program Explanation
- First condition is false, second is true.
- Only the matching block is executed.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.
Where will you use it?
- grade systems
- eligibility checks
- login validation
आम गलतियाँ (Common Mistakes)
- Using = instead of ==.
- Missing braces in multi-line blocks.
अभ्यास (Practice Tasks)
- Check pass/fail from marks.
- Find greatest of three numbers.
सारांश
if, else-if and else Statements एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.