/    /  Python – While Loop

Python – While Loop:

In this tutorial, we will learn about while loop. In python, while loop is used to iterate until the condition is satisfied. If the condition given is not satisfied in the first iteration itself, the block of code inside the loop will not get executed.

In the below example, we have assigned the value of x as zero and started the while loop until the value of x is less than 10 and print the values.

Example:

>>> x=0

>>> while x<10:

...     x=x+1

...     print(x)

...

Below is the Output:

1

2

3

4

5

6

7

8

9

10

Just changed the values for the above example and below is the output.

>>> x=100

>>> while x<110:

...     x=x+1

...     print(x)

...

Belo

w is the output:

101

102

103

104

105

106

107

108

109

110