This statement allows the user to use if
block inside the other if
block. And the inner if
statement is executed only if the outer if
statement’s condition is true.
Syntax
Syntax of nested if
statement in C:
1 2 3 4 5 6 7 8 | if(condition1) { //block of code to be executed if(condition2) { //block of code to be executed } } |
nested if Flowchart:
Example of nested if statement in C:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> int main() { // local variable int num1 = 60; int num2 = 90; // first if statement if (num1 > 50) { // if inside if statement if (num2 > 80) { printf("Actual value of num1 is : %d\n", num1); printf("Actual value of num2 is : %d\n", num2); } } return 0; } |
The output of nested if statement in C.
Actual value of num1 is : 60
Actual value of num2 is : 90