Python while Keyword

Example

Print x as long as x is less than 9:

x = 0
while x < 9:
  print(x)
  x = x + 1

Run Instance

Definition and Usage

The while keyword is used to create a while loop.

The while loop will continue until the statement is false.

related pages

Please use for Keyword to create a for loop.

Please use break Keyword to break the loop.

Please visit our Python While Loop Tutorial Learn more about the while loop in Chinese.