Another type of loop is called a while loop.
A while loop runs as long as a condition is true.
Be careful.
If the condition never becomes false, it will run forever.
Okay, so please pay attention to this.
We have an example.
Count equals to five while count greater than zero.
Go and print count.
And here we need to decrease count by one.
Because if we remove this line it will run forever.
Because five is always greater than zero.
And this condition is always true.
And we are going to loop for infinity and make our computer crashes, make, uh, and make the system
blocks or uh, the application not responding.
So please pay attention.
This is a very important thing we need to pay attention for while count greater than zero.
Go and execute print count.
Go and print the count value and decrease with every iteration the count by one.
Let's run the cell count five, four, three, two, one and blast off.
Okay, so we exit this loop and execute this line whenever the loop finish executing okay.
Also we can introduce the else statement with while so here else print.
For example count is no longer than zero.
Let me run 54321.
And with the else statement we can run a block of code once when the condition no longer is true.
So here zero greater than zero no go and execute the else statement by printing count is no longer than
zero.
Okay, so we can use the else statement with the for and with the while loop.
Okay, this is a very good example.
Another example.
Keep asking until the user types quit.
So we have this command which is a string variable.
Empty string variable.
While command dot lower doesn't equal to quit command input, enter a word or quit to exit.
If command equals to quit, go and type for you typed command.
Otherwise go and make goodbye.
Okay.
Enter a word or quit.
To exit any word like this.
Click enter.
You typed this another way.
Alice.
Let me type here.
Alice, you typed Alice.
You keep, uh, printing the input until you put quit.
Click quit, and you can notice that the program quits and display a goodbye message.