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:

1

2

3

4

5

6

7

8

9

>>>x=0

>>>whilex<10:

...x=x+1

...print(x)

...

Below is the Output:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

1

2

3

4

5

6

7

8

9

10

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