C Programming/Conditional statements

C if–else Statement

Updated on January 8, 2026
1 min read

if–else Statement in C Programming

if–else Statement

Explanation

The if–else statement is used when two possible actions exist. If the condition is true, one block runs; otherwise, the other block runs.

Syntax

if (condition) {
    // true block
} else {
    // false block
}

Flowchart

https://media.geeksforgeeks.org/wp-content/uploads/20230220123250/flowchart_of_if_else_in_c.png

Real-Life Example

Situation:

 If the traffic signal is green, go. Otherwise, stop.

Program

c
1
2#include <stdio.h>
3
4int main() {
5    int signal = 0;
6
7    if (signal == 1)
8        printf("Go");
9    else
10        printf("Stop");
11
12    return 0;
13}