The while loop is also known as a pre-tested loop. In general, a while loop allows a part of the code to be executed as long as the given condition is true.
It can be viewed as a repeating if statement. The while loop is mostly used in the case where the number of iterations is not known in advance.
The syntax is given below.
- while expression:
- statements
Here, the statements can be a single statement or the group of statements. The expression should be any valid python expression resulting into true or false. The true is any non-zero value.

Example 1
- i=1;
- while i<=10:
- print(i);
- i=i+1;
Output: