Learn Before
Code
While Loops
While loops can allow a programmer to execute the same block of code repeatedly while a condition evaluates to true. The condition may be a result of a comparison, or the value of a variable. Non-zero variables and non-empty collections will evaluate to true, while the opposite will evaluate to false.
x = 5 while x > 0: print(f"{x} seconds to launch") x = x - 1 print("Take Off!")
Result:
5 seconds to launch 4 seconds to launch 3 seconds to launch 2 seconds to launch 1 second to launch Take Off!
0
2
Updated 2021-02-03
Tags
Python Programming Language
Data Science