Conditional Statements
Conditional Statements
Processes or operations
• If Statement
• If-Else Statement
• Nested If-Else Statement
• Switch Statement
if statement if-else if-else-if Nested if-else
false
Condition
true
Statement if
Condition is verified
Exit
If-Else Statement
• The if-else statement provides an alternative block of code to execute
if the condition is false.
• Syntax:
Flowchart of if-else Statement
Start
false
Condition
true
Exit
Nested If-Else Statement
• Nesting involves placing one conditional statement inside another.
• It allows for multiple levels of decision-making.
• Example:
Nested If-Else Statement
Start
Condition false
1
true Statement if ‘Condition1’
is not verified
Condition false
2
Statement if ‘Condition2’
is not verified
true
Condition false
Statement if ‘Condition n’
n is not verified
Exit
Example
• Write a C program that displays a student's grade based on their
average
Algorithmic notation
Switch Statement
• The switch statement allows to select one of many code blocks to be
executed.
• Useful when there are multiple cases to consider.
• Syntax:
Example of switch Statement
Flowchart of Switch
Switch conditional
Statement
true
Case 1
false Statement;
Break;
true
Case 2
Statement;
false Break;
Statement;
default
Break;