C Tutorial · Chapter 12 of 16
C While Loop
Repeat while a condition stays true.
while checks the condition before each repetition.
Update the counter inside the loop or you may create an infinite loop.
While sample
Try it Yourself »
#include <stdio.h>
int main(void) {
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}
return 0;
}
Classroom Tips
- Know your start value, stop condition, and update step.