capypad
0 day streak
c / beginner
Snippet

The While Loop

The while loop repeats a block of code as long as a specified condition remains true. It is useful when the number of iterations is not known in advance.

snippet.c
c
1
2
3
4
5
int count = 1;
while (count <= 3) {
printf("Count is %d\n", count);
count++;
}
Breakdown
1
while (count <= 3)
Checks if count is less than or equal to 3 before each loop.
2
count++;
Increments the count variable to eventually end the loop.