python / beginner
Snippet
The While Loop
A while loop repeatedly executes a block of code as long as a specified condition remains True.
snippet.py
1
2
3
4
counter = 1while counter < 4:print("Iteration")counter = counter + 1
Breakdown
1
counter = 1
Initialize a variable to keep track of the count.
2
while counter < 4:
Check if the counter is less than 4 before each loop run.
3
counter = counter + 1
Increase the counter value by 1 to eventually stop the loop.