---
title: "While loop with syntax and flowchart"
subject: "Computer Programming"
chapter: 5
key: "semester_1/computer_programming:while-loop-syntax-flowchart"
source: https://www.bctengineer.com/q/semester_1/computer_programming/while-loop-syntax-flowchart
site: BCT Engineering
---

# While loop with syntax and flowchart

Computer Programming · Chapter 5: Control statements

- Asked in: 2074 Chaitra, 4 marks
- Video: [While loop in C Programming with examples](https://www.youtube.com/watch?v=A8oirIz1qPs) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/while-loop-syntax-flowchart
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

Explain about while loop with its syntax and flowchart.

## Short answer

The while loop is an entry-controlled loop that tests a condition before executing the body. Its syntax: initialisation; while (condition) { statements; update; }. The flowchart shows a condition diamond; if true, execute body and update then loop back; if false, exit.

## Answer

The `while` loop is an entry-controlled loop: the condition is tested first, and the body is executed repeatedly as long as the condition is true. If the condition is false at the start, the body never executes.

**Syntax:**
```text
initialisation;
while (condition)
{
    statements;
    update;
}
```

**Flowchart:**
```text
      [ initialisation ]
              |
        +---->|
        |     v
        | < condition ? >--False--> next statement
        |     | True
        | [ body + update ]
        +-----+
```

**Example:**
```c
#include <stdio.h>
int main(void)
{
    int i = 1, sum = 0;
    while (i <= 5)
    {
        sum += i;
        i++;
    }
    printf("Sum of 1 to 5 = %d\n", sum);
    return 0;
}
```
Output:
```text
Sum of 1 to 5 = 15
```

## Check yourself

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

1. Why is while an entry-controlled loop?
   A. Condition is tested before the body
   B. Condition is tested after the body
   C. The body runs once before testing
   D. It has no condition
   Answer: A. The test comes first, so the body may never run. (Key point: Entry-controlled)

2. What happens if the while condition is false at the start?
   A. The body executes once
   B. The body never executes
   C. Compiler error
   D. Infinite loop
   Answer: B. Entry test fails, so the loop is skipped. (Key point: False at start)

3. Why must a variable in the condition be updated inside the loop?
   A. To declare the variable
   B. To avoid using braces
   C. Otherwise the condition may stay true and loop forever
   D. To make the loop entry-controlled
   Answer: C. Without an update the condition may never become false. (Key point: Update)

4. What does the example print for i from 1 to 5?
   A. Sum of 1 to 5 = 10
   B. Sum of 1 to 5 = 5
   C. Sum of 1 to 5 = 120
   D. Sum of 1 to 5 = 15
   Answer: D. 1+2+3+4+5 = 15. (Key point: Example sum)

## Related in Computer Programming

- [Syntax of while loop](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-while) — Computer Programming, chapter 5
- [do...while versus for/while loops](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Ado-while-vs-for-while) — Computer Programming, chapter 5, asked 2×
