Section 1/5while Loop Structure
while Loop Structure
Explore this concept
Mastering while Loops
While loops execute code repeatedly while a condition remains true. They're ideal for situations where the number of iterations is unknown upfront.
while Loop Structure
# Basic countdownn = 3while n > 0:print(n)n -= 1
→
3\n2\n1Key components:
- Initial condition:
n = 3 - Loop condition:
n > 0 - Modifier:
n -= 1