Episode 4.1: Basic Conditional Statements (if...else)

Youtube Thumbnails (20).png

YouTube link : Click here

Objective

Introduce basic conditional statements (if...else) and show how to check simple conditions in a program.


Concept Brief

In this sub-episode, we’ll focus on the simplest form of conditional logic using if...else statements. This allows a program to make decisions based on a single condition. If the condition is true, it runs one block of code; if false, it runs another.


Real-World Analogy

Imagine you are deciding whether to go outside. If it’s raining, you stay inside; if not, you go outside. This is the basic idea behind an if...else statement.

Leo Movie example !


C++ Example: Check if the Number is Positive or Negative

#include <iostream>
using namespace std;

int main() {
    int number;
    cout << "Enter a number: ";
    cin >> number;

    if (number > 0) {
        cout << "The number is positive." << endl;
    } else {
        cout << "The number is not positive (it’s either negative or zero)." << endl;
    }

    return 0;
}

Explanation: If the input number is greater than zero, it prints that the number is positive. Otherwise, it assumes the number is either negative or zero.