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