WHILE LOOP
A
while
loop allows your code to repeat itself based on a condition you set. EXAMPLE :
counter = 0
while counter < 10:
print(counter)
counter +=1
Infinite Loop
You have to be really careful that you don't accidentally invoke an infinite loop! This is where the computer will loop code until the end of time. Without a break. Forever.
This is just saying "count to 10 by 1 each time." to make the loop end.
Don't forget, if your condition is a >
then you might need to -=
. This will subtract from the variable instead of adding to it.
EXAMPLE :
counter = 0
while counter < 10:
print(counter)
counter += 1
Comments
Post a Comment