While loops

--Originally published at Sierra's Blog

While loops are used to tell python  I want to do this until this happens this is how you can use it:

while expression:

statement

 

for example, I made a program that guesses the number in which you’re thinking based on questions. This program uses all the stuffs that we’ve seen till now, try to understand it, it will help you a lot because this way you’ll see the way I program and maybe you’ll start thinking in other possible ways to come up with the same result:

while.png

The functions of the while loop is to keep repeating the code until the expression becomes FALSE and since the while expression is: while the Min number isn’t equal as the Max number keep asking the user, the program will only stop until it finds the number that you were thinking.

Here’s a video tutorial from Khan Academy explaining how to use the while loops: