The while Loop

Another type of loop in python is while loop. Let's learn how a while loop works in python

We'll cover the following...

The while loop is also used to repeat sections of code, but instead of looping n number of times, it will only loop until a specific condition is met. Let’s look at a very simple example:

Press + to interact
i = 0
while i < 10:
print(i)
i = i + 1

The while loop is kind of like a conditional statement. Here’s what this code means: while the variable i is less than ten, print it out. Then at the end, we increase i’s value by one. ...