Table of Contents

    Decision Making

    Programming Mastery

    Decision Making

    Learn how programs make choices using conditions, selection statements, comparison operators, logical operators, and branching logic.

    What is Decision Making in Programming?

    Decision making in programming means allowing a program to choose what action to perform based on a condition.

    In simple words, decision making helps a program ask a question such as “Is this condition true?”. If the condition is true, one block of instructions runs. If the condition is false, another block may run or the program may skip that part.

    Decision making allows a program to choose different paths based on conditions.

    Without decision making, programs would only execute statements one after another in a fixed sequence. With decision making, programs become dynamic, interactive, and able to respond to different inputs and situations.

    Easy Real-Life Example

    Decision Making as Choosing an Action

    Imagine you are going outside. You check the weather. If it is raining, you take an umbrella. Otherwise, you go without an umbrella.

    This is decision making. You check a condition and choose an action based on the result.

    IF it is raining THEN
        Take umbrella
    ELSE
        Go without umbrella
    END IF

    Why is Decision Making Important?

    Decision making is important because real programs must react differently in different situations. A calculator must choose an operation. A login system must check credentials. A student result program must decide pass or fail.

    Importance of Decision Making

    • It allows programs to choose between different actions.
    • It helps programs respond to user input.
    • It makes programs interactive and dynamic.
    • It supports validation and error handling.
    • It helps implement business rules and conditions.
    • It allows programs to handle multiple scenarios.
    • It is essential for games, forms, calculators, login systems, and menu-based programs.
    • It is one of the core parts of control flow.

    Decision Making in Control Flow

    Decision making is part of selection control flow. Selection means choosing one path from two or more possible paths.

    INPUT marks
    
    IF marks >= 35 THEN
        DISPLAY "Pass"
    ELSE
        DISPLAY "Fail"
    END IF

    In this example, the program makes a decision based on the value of marks. If the condition is true, it displays Pass. Otherwise, it displays Fail.

    What is a Condition?

    A condition is an expression that evaluates to either true or false.

    Conditions are the foundation of decision making because the program uses them to decide which path to follow.

    Examples of Conditions

    age >= 18
    marks >= 35
    password == correctPassword
    quantity > 0
    temperature > 30

    Each of these conditions can be true or false depending on the value of the variables.

    Comparison Operators in Decision Making

    Comparison operators are used to compare values. The result of a comparison is usually true or false.

    Operator Meaning Example Result Idea
    == Equal to marks == 100 True if marks are exactly 100.
    != Not equal to password != "" True if password is not empty.
    > Greater than price > 0 True if price is greater than 0.
    < Less than age < 18 True if age is less than 18.
    >= Greater than or equal to marks >= 35 True if marks are 35 or more.
    <= Less than or equal to marks <= 100 True if marks are 100 or less.

    Main Types of Decision Making

    Decision making can be written in different forms depending on how many choices the program needs to handle.

    Simple IF

    Executes a block only when a condition is true.

    IF ELSE

    Chooses between two possible paths.

    ELSE IF Ladder

    Checks multiple conditions one by one.

    Nested IF

    Places one decision inside another decision.

    1. Simple IF Statement

    A simple IF statement runs a block of code only if the condition is true. If the condition is false, the block is skipped.

    Syntax Idea

    IF condition THEN
        statements
    END IF

    Example

    INPUT marks
    
    IF marks >= 35 THEN
        DISPLAY "You passed"
    END IF

    If marks are greater than or equal to 35, the message is displayed. If marks are less than 35, nothing is displayed from this decision block.

    2. IF ELSE Statement

    An IF ELSE statement is used when there are two possible outcomes.

    Syntax Idea

    IF condition THEN
        statements when condition is true
    ELSE
        statements when condition is false
    END IF

    Example: Pass or Fail

    INPUT marks
    
    IF marks >= 35 THEN
        DISPLAY "Pass"
    ELSE
        DISPLAY "Fail"
    END IF

    This program chooses one of two paths: pass or fail.

    3. ELSE IF Ladder

    An ELSE IF ladder is used when a program needs to check multiple conditions.

    Syntax Idea

    IF condition1 THEN
        statements for condition1
    ELSE IF condition2 THEN
        statements for condition2
    ELSE IF condition3 THEN
        statements for condition3
    ELSE
        default statements
    END IF

    Example: Grade Calculation

    INPUT marks
    
    IF marks >= 90 THEN
        DISPLAY "Grade A"
    ELSE IF marks >= 75 THEN
        DISPLAY "Grade B"
    ELSE IF marks >= 60 THEN
        DISPLAY "Grade C"
    ELSE IF marks >= 35 THEN
        DISPLAY "Pass"
    ELSE
        DISPLAY "Fail"
    END IF

    The program checks conditions from top to bottom. When one condition becomes true, that block executes.

    Important: In an ELSE IF ladder, the order of conditions matters. More specific or higher-priority conditions should usually come first.

    4. Nested IF Statement

    A nested IF statement means writing one decision inside another decision.

    Nested decisions are useful when one condition should be checked only after another condition is true.

    Example: Voting Eligibility

    INPUT age
    INPUT hasVoterID
    
    IF age >= 18 THEN
        IF hasVoterID == true THEN
            DISPLAY "Eligible to vote"
        ELSE
            DISPLAY "Voter ID required"
        END IF
    ELSE
        DISPLAY "Not eligible due to age"
    END IF

    First, the program checks age. Only if the age condition is true does it check whether the user has a voter ID.

    5. Multiple Choice Decision: CASE / SWITCH

    A CASE or SWITCH structure is used when the program needs to choose from multiple fixed options.

    This is common in menu-driven programs and calculators.

    Example: Calculator Operation

    INPUT operation
    
    CASE operation OF
        "+":
            DISPLAY "Addition selected"
        "-":
            DISPLAY "Subtraction selected"
        "*":
            DISPLAY "Multiplication selected"
        "/":
            DISPLAY "Division selected"
        DEFAULT:
            DISPLAY "Invalid operation"
    END CASE

    This decision structure chooses an action based on the value of operation.

    Logical Operators in Decision Making

    Logical operators are used when a decision depends on more than one condition.

    Logical Operator Meaning Example
    AND All conditions must be true. marks >= 0 AND marks <= 100
    OR At least one condition must be true. choice == "Y" OR choice == "N"
    NOT Reverses true or false. NOT isLoggedIn

    Example: Valid Marks Check

    INPUT marks
    
    IF marks >= 0 AND marks <= 100 THEN
        DISPLAY "Valid marks"
    ELSE
        DISPLAY "Invalid marks"
    END IF

    The marks are valid only if both conditions are true.

    Example: Decision Making in a Simple Calculator

    INPUT firstNumber
    INPUT secondNumber
    INPUT operation
    
    IF operation == "+" THEN
        DISPLAY firstNumber + secondNumber
    
    ELSE IF operation == "-" THEN
        DISPLAY firstNumber - secondNumber
    
    ELSE IF operation == "*" THEN
        DISPLAY firstNumber * secondNumber
    
    ELSE IF operation == "/" THEN
        IF secondNumber != 0 THEN
            DISPLAY firstNumber / secondNumber
        ELSE
            DISPLAY "Division by zero is not allowed"
        END IF
    
    ELSE
        DISPLAY "Invalid operation"
    END IF

    This calculator uses decision making to choose the correct arithmetic operation.

    Example: Login Decision

    INPUT username
    INPUT password
    
    IF username == "admin" AND password == "1234" THEN
        DISPLAY "Login successful"
    ELSE
        DISPLAY "Invalid username or password"
    END IF

    This program checks two conditions together. Both username and password must be correct for login to succeed.

    Example: Discount Decision

    INPUT totalAmount
    
    IF totalAmount >= 5000 THEN
        DISPLAY "Discount: 20%"
    ELSE IF totalAmount >= 2000 THEN
        DISPLAY "Discount: 10%"
    ELSE
        DISPLAY "No discount"
    END IF

    This program decides the discount based on the total purchase amount.

    Decision Making in Flowcharts

    In flowcharts, decision making is usually represented using a diamond symbol. The condition is written inside the diamond, and the flow branches into paths such as Yes and No.

    START
      ↓
    INPUT marks
      ↓
    Is marks >= 35?
      ├── Yes → DISPLAY "Pass"
      └── No  → DISPLAY "Fail"
      ↓
    STOP

    The diamond represents the decision point where the program chooses a path.

    Decision Making Trace Table

    A trace table helps students understand how a decision is evaluated step by step.

    INPUT marks
    
    IF marks >= 35 THEN
        DISPLAY "Pass"
    ELSE
        DISPLAY "Fail"
    END IF
    Test Case marks Condition: marks >= 35 Output
    1 80 true Pass
    2 25 false Fail
    3 35 true Pass

    Common Beginner Mistakes

    Mistakes

    • Using assignment operator instead of comparison operator.
    • Writing conditions in the wrong order.
    • Forgetting the ELSE block for default cases.
    • Using too many nested decisions.
    • Writing unclear or overly complex conditions.
    • Not testing both true and false cases.
    • Forgetting boundary values such as 35, 0, or 100.
    • Repeating the same code inside multiple branches.

    Better Habits

    • Use comparison operators carefully.
    • Write conditions in a logical order.
    • Always handle the default case when needed.
    • Keep decision blocks simple.
    • Use meaningful variable names.
    • Test true, false, and boundary cases.
    • Use logical operators only when needed.
    • Use indentation to make branches readable.

    How Decision Making Helps Debugging

    Decision making can sometimes cause logical errors. Debugging decision logic means checking whether the correct condition is being evaluated and whether the correct branch is running.

    Debugging Questions

    • What condition is being checked?
    • Is the condition true or false?
    • Which branch should execute?
    • Which branch actually executed?
    • Are comparison operators correct?
    • Are logical operators used correctly?
    • Are boundary values handled properly?
    • Is the default case handled?

    Best Practices for Decision Making

    Good decision-making logic should be clear, readable, and easy to test.

    Recommended Practices

    • Write simple and clear conditions.
    • Use meaningful variable names in conditions.
    • Use indentation to show decision blocks clearly.
    • Test all possible branches.
    • Test boundary values carefully.
    • Use ELSE for default or fallback cases.
    • Avoid deeply nested decisions when possible.
    • Use logical operators only when they improve clarity.
    • Use comments only when the decision logic is not obvious.
    • Use flowcharts or pseudocode for complex decisions.

    Prerequisites Before Learning Decision Making

    To understand decision making properly, students should already know a few basic programming concepts.

    Basic Prerequisites

    • What is control flow?
    • Sequential execution.
    • Statements and expressions.
    • Variables and constants.
    • Data types.
    • Comparison operators.
    • Logical operators.
    • Input and output.
    • Basic input validation.
    • Dry run and trace table basics.

    Practice Activity: Identify the Decision

    Read the scenarios and identify the condition used for decision making.

    Scenario Possible Condition
    A student passes if marks are 35 or more. ________________________
    A person can vote if age is 18 or more. ________________________
    A product gets discount if total amount is 2000 or more. ________________________
    A login succeeds if username and password are correct. ________________________
    A calculator should not divide by zero. ________________________

    Sample Answers

    Scenario Possible Condition
    A student passes if marks are 35 or more. marks >= 35
    A person can vote if age is 18 or more. age >= 18
    A product gets discount if total amount is 2000 or more. totalAmount >= 2000
    A login succeeds if username and password are correct. username == correctUsername AND password == correctPassword
    A calculator should not divide by zero. secondNumber != 0

    Mini Quiz

    1

    What is decision making in programming?

    Decision making means allowing a program to choose an action based on a condition.

    2

    What is a condition?

    A condition is an expression that evaluates to true or false.

    3

    What is an IF ELSE statement used for?

    An IF ELSE statement is used to choose between two possible paths.

    4

    When should ELSE IF be used?

    ELSE IF should be used when multiple conditions need to be checked.

    5

    Give one example of decision making.

    Checking whether marks are greater than or equal to 35 to decide pass or fail is an example of decision making.

    Interview Questions on Decision Making

    1

    Define decision making in programming.

    Decision making is the process of controlling program execution by evaluating conditions and choosing which block of code should run.

    2

    What is the difference between IF and IF ELSE?

    IF executes a block only when the condition is true, while IF ELSE chooses between one block for true and another block for false.

    3

    What is nested decision making?

    Nested decision making means placing one decision statement inside another decision statement.

    4

    Why are comparison operators important in decision making?

    Comparison operators help create conditions by comparing values and producing true or false results.

    5

    When is CASE or SWITCH useful?

    CASE or SWITCH is useful when a program must choose from multiple fixed options, such as menu choices or calculator operations.

    Quick Summary

    Concept Meaning
    Decision Making Choosing an action based on a condition.
    Condition An expression that evaluates to true or false.
    IF Runs code only if condition is true.
    IF ELSE Chooses between two paths.
    ELSE IF Checks multiple conditions.
    Nested IF A decision inside another decision.
    CASE / SWITCH Chooses from multiple fixed options.
    Best Practice Keep conditions clear, test all branches, and handle default cases.

    Final Takeaway

    Decision making is a key part of control flow. It allows programs to choose different paths based on conditions. In the Programming Mastery Course, students should understand decision making through simple ideas such as IF, IF ELSE, ELSE IF, Nested IF, and CASE / SWITCH. A good programmer writes clear conditions, handles all possible outcomes, and tests both true and false paths carefully.