Syntax

Python While Loop Syntax

In Python, while loop: repeats while a condition is true — while x < 10: x += 1

Quick Answer

Syntax
while x < 10: x += 1
PythonSyntax

While Loop

Code example
while x < 10: x += 1

Repeats while a condition is true.

Learn More

How to while loop in Python

  1. Open your Python file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Python While Loop Syntax

Use while x < 10: x += 1.

Related Syntax References

Frequently asked questions

What is the Python syntax for while loop?

Use this pattern: while x < 10: x += 1

Can I copy this Python code example?

Yes. Use Copy code and adapt the example to your program.

Is this Python syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify