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

# Syntax of while loop

Computer Programming · Chapter 5: Control statements

- Asked in: 2067 Asar, 2 marks
- Video: [C Programming Tutorial 76 -  While Loop](https://www.youtube.com/watch?v=OfJJsEIO1kE) — Caleb Curry
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-while
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

Write the syntax used in C programming language for while.

## Short answer

while (condition) { statements; } is the syntax. The condition is evaluated first; the loop body executes only while it is true. It is an entry-controlled loop requiring prior initialization and in-loop updating of the condition variable.

## Answer

**Syntax:**
```text
while (condition)
{
    statements;
}
```
The condition is evaluated first; the body is executed as long as it is true (non-zero). It is an entry-controlled loop, and the variable in the condition must be initialised before it and updated inside the loop.

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

## Check yourself

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

1. Correct while syntax?
   A. while { condition }
   B. while (condition) { statements; }
   C. while (condition); {..}
   D. while condition do
   Answer: B. Standard. (Key point: Syntax)

2. What's evaluated first?
   A. Body
   B. Update
   C. Condition
   D. Initialisation after
   Answer: C. Entry-controlled. (Key point: Order)

3. What must be done to loop variable?
   A. Nothing
   B. Declared after
   C. Const
   D. Initialised before, updated inside
   Answer: D. Avoid infinite loop. (Key point: Setup)

## Related in Computer Programming

- [While loop with syntax and flowchart](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Awhile-loop-syntax-flowchart) — Computer Programming, chapter 5
- [Define programming language](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-programming-language) — Computer Programming, chapter 1, asked 3×
- [Syntax of if...else](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-if-else) — Computer Programming, chapter 5
- [Syntax of static](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-static) — Computer Programming, chapter 6
- [Syntax of struct](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-struct) — Computer Programming, chapter 8
- [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×

## Related in other subjects

- [8086 assembly language operators](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8086-operators) — Microprocessor, chapter 3, asked 3×
