Home | Computer Science

<
WHILE LOOP

Defination

The while loop is used to repeat a section of code an unknown number of times until a specific condition is met.


WHILE LOOP Syntax of for loop is
while (condition) {
// code block to be executed
}
NOTE
Note: Do not forget to increase the variable used in the condition (i++), otherwise the loop will never end!
Program
INPUT

#include <stdio.h> main() { int i = 0; while (i < 5) { printf("%d\n", i); i++; } getch(); }

OUTPUT