While Loops
Table of contents
Description
While loops are used to execute a block of code until a condition fails.
- Python Docs: The while statement
Examples
Infinite Loops
An infinite loop is a common error with that occurs when a condition is never given the opportunity to fail. The loop below is an infinite loop, because the cash variable is never decremented. Therefore, the condition never changes and will remain true.
Run the program below, and observe the infinite loop. Then, paste cash -= taco_price
on line 6 and run the program again.