while Loop

noun

say it: “WYL loop” /ˈwaɪl lup/

A loop that keeps repeating its block as long as its condition is true, checking the condition before each round.

What is a while loop?

A while loop keeps repeating as long as its condition stays true.

fuel = 3
while fuel > 0:
    print("Driving... fuel left:", fuel)
    fuel -= 1
print("Out of fuel")

In a sentence

  • “The while loop kept asking for a PIN until the user typed the right one.”
  • “A while loop whose condition never turns false runs forever.”

Level: Apprentice · More Python terms at this level

Updated

In other subjects