Introduction
Conditional statements assist you in determining based on certain situations. These conditions are particular by means of a set of conditional statements having boolean expressions, which might be evaluated to a boolean value true or false.

Also Read About, Sum of Digits in C, C Static Function
Type of Conditional statement
1. If the statement
2. If-Else statement
3. Nested If-else statement
4. If-Else If ladder
5. Switch statement
1. If statement
It is one of the effective conditional statements if the statement is responsible for modifying the flow of execution of a program. Suppose the statement is continually used with a condition. This condition is evaluated first before executing any statement inside the body of If.
Syntax
if(expression)
{
//code to be executed
}
Example
Output
enter the number 4
4 number is even
Also see, Floyd's Triangle in C
Steps for if conditional statement in C
These are the steps for using an if conditional statement in C:
- Write the if keyword: Start with if.
- Add a condition in parentheses (): Put the condition you want to test inside parentheses.
- Add curly braces {}: Use curly braces to enclose the code that should run if the condition is true.
- Write the code inside the curly braces: Add the statements you want to execute when the condition is true.
2. If-Else statement
In this form of a construct, if the value of test-expression is true, then the true block of statements may be finished. If the value of the test expression is false, then the false block of statements may be executed. In any type of case, the control can be automatically transferred to the statements performing outside the block of If after the execution.
Syntax
if(expression)
{
//Statements
}
else
{
//Statements
}
Example
Output
enter the number5
5 number is oddSteps to use if-else conditional statement in C
These are the steps for using an if-else conditional statement in C:
- Write the if keyword: Start with if.
- Add a condition in parentheses (): Put the condition to test inside the parentheses.
- Add curly braces {} for the if block: Include the code that should run if the condition is true.
- Write the else keyword: After the if block, use else.
- Add curly braces {} for the else block: Include the code that should run if the condition is false.
3. Nested If-else statement
The nested if...else statement is used while a program requires a couple of test expressions. It's also called a multi-way selection statement. When a series of decisions are involved in a statement, we use the if-else statement in nested form.
Syntax
if( expression )
{
if( expression1 )
{
statement-block1;
}
else
{
statement-block 2;
}
}
else
{
statement-block 3;
}
Example
Output
b is greatestSteps for Nested if-else conditional statement in C
These are the steps for using a nested if-else conditional statement in C:
- Start with the outer if keyword: Begin with an if statement.
- Add a condition in parentheses (): Place the condition for the outer if statement inside parentheses.
- Use curly braces {} for the outer if block: Include the code to run if the outer condition is true inside curly braces.
- Inside the outer if block, start with an inner if keyword: Write another if statement inside the block of the outer if.
- Add a condition in parentheses (): Put the condition for the inner if statement inside parentheses.
- Use curly braces {} for the inner if block: Include the code to run if the inner condition is true inside curly braces.
- Write else for the inner if (optional): After the inner if block, use else to handle cases where the inner condition is false.
- Add curly braces {} for the inner else block (optional): Include the code to run if the inner condition is false inside curly braces.
- Write else for the outer if (optional): After the outer if block, use else to handle cases where the outer condition is false.
- Add curly braces {} for the outer else block (optional): Include the code to run if the outer condition is false inside curly braces.
4. If-Else If ladder
The if-else-if statement is used to execute a code from multiple conditions. It's also known as a multipath decision statement. It is a sequence of if..else statements in which each if statement is associated with an else if statement and remaining might be an else statement.
Syntax
if(condition1)
{
//statements
}
else if(condition2)
{
//statements
}
else if(condition3)
{
//statements
}
else
{
//statements
}
Example
Output
enter a number 21
divisible by 75. Switch statement
Switch statement reacts as a substitute for a long if-else-if ladder. This is used to check a list of cases. A switch statement includes one or more case labels that might be tested against the switch expression. While the expression matches a case, then the associated statements with that case could be executed.
Syntax
Switch (expression)
{
case value1:
//Statements
break;
case value 2:
//Statements
break;
case value 3:
//Statements
case value n:
//Statements
break;
Default:
//Statements
}
Example
Output
Well done
Also see, Tribonacci Series. and Short int in C Programming




