---
title: "Nested if with flowchart"
subject: "Computer Programming"
chapter: 5
key: "semester_1/computer_programming:nested-if-flowchart"
source: https://www.bctengineer.com/q/semester_1/computer_programming/nested-if-flowchart
site: BCT Engineering
---

# Nested if with flowchart

Computer Programming · Chapter 5: Control statements

- Asked in: 2071 Chaitra, 2 marks
- Video: [nested if statement in c programming | nested if statement syntax,flowchart and example program in c](https://www.youtube.com/watch?v=SdYWiM7i8v4) — Learn Coding
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/nested-if-flowchart
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

Illustrate nested IF statement with its flowchart.

## Short answer

A nested if is an if statement placed inside another if or else. The inner condition is evaluated only when the outer condition is true. The flowchart branches from condition1: if true, evaluate condition2, else execute the outer else block.

## Answer

A **nested if** is an `if` statement placed inside another `if` or `else`. The inner condition is checked only when the outer condition is satisfied.

**Syntax:**
```text
if (condition1)
{
    if (condition2)
        statement A;
    else
        statement B;
}
else
    statement C;
```

**Flowchart:**
```text
       < condition1 ? >
        True |        | False
    < condition2 ? >  [ C ]
     True |    | False   |
       [ A ]  [ B ]      |
         +-----+---------+
               |
          next statement
```

**Example (largest of three):**
```c
#include <stdio.h>
int main(void)
{
    int a = 15, b = 9, c = 22;
    if (a > b)
    {
        if (a > c)
            printf("%d is largest\n", a);
        else
            printf("%d is largest\n", c);
    }
    else
    {
        if (b > c)
            printf("%d is largest\n", b);
        else
            printf("%d is largest\n", c);
    }
    return 0;
}
```
Output:
```text
22 is largest
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is a nested if?
   A. Two ifs one after the other
   B. An if with no else
   C. An if using a loop
   D. An if placed inside another if or else
   Answer: D. Nested means one if inside another. (Key point: Definition)

2. When is the inner condition checked?
   A. Only when the outer condition is satisfied
   B. Always before the outer
   C. Only when outer is false
   D. Never
   Answer: A. The inner if is inside the outer true block. (Key point: Inner check)

3. a=15, b=9, c=22 in the largest-of-three program prints?
   A. 15 is largest
   B. 22 is largest
   C. 9 is largest
   D. Nothing
   Answer: B. a>b, then a>c is false so c is printed. (Key point: Example)

## Related in Computer Programming

- [Compare switch and if-else-if ladder](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-ifelse-ladder) — Computer Programming, chapter 5, asked 2×
- [Conditional operator vs if-else; digit sum](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aconditional-operator-vs-ifelse) — Computer Programming, chapter 5

## Related in other subjects

- [Converse, inverse, contrapositive of prime statement](https://www.bctengineer.com/question.md?key=semester_4%2Fdiscrete_structure%3Aconverse-inverse-contrapositive-prime) — Discrete Structure, chapter 1, asked 2×
- [Converse etc. of temple statement](https://www.bctengineer.com/question.md?key=semester_4%2Fdiscrete_structure%3Aconverse-contrapositive-temple-saturday) — Discrete Structure, chapter 1
- [Contrapositive and inverse: snow statement](https://www.bctengineer.com/question.md?key=semester_4%2Fdiscrete_structure%3Acontrapositive-inverse-snow-home) — Discrete Structure, chapter 1
- [Euler's theorem statement with sin u example](https://www.bctengineer.com/question.md?key=semester_2%2Fmathematics%3Aeuler-s-theorem-statement-sin) — Mathematics, chapter 1, asked 3×
