Control statements in C are used to control the flow of execution of a program. By default, a C program executes statements sequentially, one after another. Control statements allow the program to make decisions, repeat operations, or jump to different parts of the code.
They play a crucial role in implementing logic and decision-making in C programs.

Decision-making statements allow a program to execute different blocks of code based on whether a given condition is true or false.
The if statement executes a block of code only when a specified condition is true.
if (condition)
{
// statements
}
If the condition evaluates to false, the statements inside the if block are skipped.
The if–else statement provides an alternative block of code
that executes when the condition is false.
if (condition)
{
// statements if true
}
else
{
// statements if false
}
This structure ensures that exactly one block of code is executed.
A nested if statement is an if statement placed inside another if or else block.
It is used when multiple conditions need to be checked.
if (condition1)
{
if (condition2)
{
// statements
}
}
Nested if statements should be used carefully to maintain program readability.
The switch statement is used to select one block of code
from multiple alternatives based on the value of an expression.
switch (expression)
{
case value1:
// statements
break;
case value2:
// statements
break;
default:
// statements
}
The break statement prevents fall-through to the next case.
The default case executes if no matching case is found.
The goto statement transfers control unconditionally to a labeled statement in the program.
goto label;
/* statements */
label:
// statements
Although supported by C, the use of goto is discouraged
because it makes programs difficult to understand and debug.
#include <stdio.h>
int main()
{
int num = 5;
if (num > 0)
printf("Positive number\n");
else
printf("Negative number\n");
switch (num)
{
case 1:
printf("One\n");
break;
case 5:
printf("Five\n");
break;
default:
printf("Other number\n");
}
return 0;
}
This program demonstrates the use of if–else and switch statements in C.
| Statement | Purpose | Usage |
|---|---|---|
| if | Tests a single condition | Simple decision making |
| if–else | Provides two alternatives | Binary decisions |
| nested if | Checks multiple conditions | Complex decisions |
| switch | Selects from multiple options | Menu-driven programs |
| goto | Unconditional jump | Avoid when possible |
switch is useful for multiple fixed choices.goto should be avoided in structured programming.