Python while Keyword

❮ Python Keywords


Example

Print x as long as x is less than 9:

x = 0

while x < 9:
  print(x)
  x = x + 1
Try it Yourself »

Definition and Usage

The while keyword is used to create a while loop.

A while loop will continue until the statement is false.


Related Pages

Use the for keyword to create a for loop.

Use the break keyword to break out of a loop.

Read more about while loops in our Python While Loops Tutorial.


❮ Python Keywords

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.