capypad
0 day streak
python / beginner
Snippet

While Loops

A while loop repeats a block of code as long as a specified condition evaluates to True.

snippet.py
python
1
2
3
4
count = 0
while count < 3:
print("Iteration:", count)
count += 1
Breakdown
1
count = 0
Initializes a counter variable to zero.
2
while count < 3:
Starts the loop and checks if the count is less than 3.
3
count += 1
Increments the counter by 1 to eventually end the loop.