Home Tutorials C Tutorial Decision Making
Decision Making

Decision Making


Decision-making structures require that the programmer specifies one or more conditions to be evaluated by the program. These statements allow your code to "think" and take different paths based on data.

1. The if Statement

The simplest form of decision-making. It executes a block of code only if the condition is true.

int age = 20;
if (age >= 18) {
    printf("You are eligible to vote.");
}

2. The if...else Statement

Provides an alternative path. If the condition is false, the else block runs.

int marks = 75;
if (marks >= 35) {
    printf("Result: Pass\n");
} else {
    printf("Result: Fail\n");
}
[Image of if-else flowchart in C programming]

3. The Nested if Statement

An if inside another if. Used when multiple conditions must be met in sequence.

int x = 10, y = 20;
if (x == 10) {
    if (y == 20) {
        printf("Both conditions are true\n");
    }
}

4. The Nested if...else (Else-If Ladder)

Used to check multiple distinct possibilities in a sequence.

int score = 85;
if (score >= 90) {
    printf("Grade: A\n");
} else if (score >= 80) {
    printf("Grade: B\n");
} else {
    printf("Grade: C\n");
}

5. The switch Statement

A cleaner way to handle multiple fixed values for a single variable.

int day = 2;
switch (day) {
    case 1: 
        printf("Monday"); 
        break;
    case 2: 
        printf("Tuesday"); 
        break;
    default: 
        printf("Other day");
}
Example

🏋️ Test Yourself With Exercises

Take our quiz on Decision Making to test your knowledge.

Browse Quizzes »