Drop links or images here to add them to the editor.

De while-loop werkt als volgt:

  1. De conditie wordt gecontroleerd.
  2. Als de conditie False is: Python slaat de while-body over en gaat verder.
  3. Als de conditie True is: de body wordt uitgevoerd.
  4. Na de body springt Python terug naar de conditie.
  5. Dit herhaalt zich totdat de conditie False wordt.
while <conditie>:
    <code die herhaald wordt>

Let op: zorg altijd dat de conditie ooit False wordt, anders loop je eindeloos.

Aftellen

print("Vanaf welk getal wil je aftellen?")
invoer = input()
tijd = int(invoer)

while tijd > 0:
    tijd -= 1
    print("tijd is", tijd)

print("AF!")