While Loop in Python

Premium

The general format of the while statement is:

1while (condition) :
2    statement
3}
4

Note that a while loop may never execute the statement. The statement is executed repeatedly until condition becomes false.

Unlike for loop which iterates over a list, for using while loop you need to have an indicator variable i and change its value within each iteration. Otherwise you will have an infinite loop.

Unlock Premium Content

Upgrade your account to access the full article, downloads, and exercises.

You'll get access to:

  • Access complete tutorials and examples
  • Download source code and resources
  • Follow along with practical exercises
  • Get in-depth explanations