🟡 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.
Level
🟡 Control Flow and Core Programming
Example File
if-else.cpp
Main Focus
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

TermMeaning / Use
conditionif, else-if and else Statements programming में Condition use होता है।
ifif, else-if and else Statements programming में If use होता है।
else ifif, else-if and else Statements programming में Else if use होता है।
elseif, else-if and else Statements programming में Else use होता है।
blockif, 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

  1. Check pass/fail from marks.
  2. 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.
Level
🟡 Control Flow and Core Programming
Example File
if-else.cpp
मुख्य फोकस
Concept + syntax + practical C++ program

इसे क्यों सीखें?

  • यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
  • यह school practicals, projects और competitive programming में बार-बार use होता है।
  • यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।

ज़रूरी Terms

Termअर्थ / उपयोग
conditionCondition if, else-if and else Statements programming में use होता है।
ifIf if, else-if and else Statements programming में use होता है।
else ifElse if if, else-if and else Statements programming में use होता है।
elseElse if, else-if and else Statements programming में use होता है।
blockBlock 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)

  1. Check pass/fail from marks.
  2. Find greatest of three numbers.

सारांश

if, else-if and else Statements एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।

← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 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ें.