c / beginner
Snippet
Repeating with while Loops
A while loop repeats a block of code as long as its condition is true. The condition is checked before every iteration of the loop.
snippet.c
1
2
3
4
int energy = 3;while (energy > 0) {energy--;}
Breakdown
1
while (energy > 0) {
The loop runs as long as the variable energy is greater than 0.
2
energy--;
Decreases the value of energy by one inside the loop.