- 2067 Asar · 2 marks
Syntax of while loop
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.
Write the syntax used in C programming language for while.
Syntax:
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:
#include <stdio.h>
int main(void)
{
int i = 1;
while (i <= 3)
{
printf("%d\n", i);
i++;
}
return 0;
}
Output:
1
2
3
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- While loop with syntax and flowchart · Computer Programming, chapter 5
- Define programming language · Computer Programming, chapter 1 · asked 3×
- Syntax of if...else · Computer Programming, chapter 5
- Syntax of static · Computer Programming, chapter 6
- Syntax of struct · Computer Programming, chapter 8
- do...while versus for/while loops · Computer Programming, chapter 5 · asked 2×
- 8086 assembly language operators · Microprocessor, chapter 3 · asked 3×