The condition-based reputation has similar structure as our decision structure. That is, we have a condition, we have a decision, and if there is a yes, then we execute plan A. If the condition is a false, then we're going to skip plan A and go to next part of the program. The only difference between this condition and the plan A and the branching is after executing plan A in the branching, we go to next part of the program. Same as the no branch. For this condition best reputation, after executing plan A, we're going to go back to the previous, to the one before the condition and then they are going to go check on the condition again, as if we were getting into this checking in a first a time. That is whenever we set to the condition is something we tested to be true, we execute plan A. Then we check the condition. Again, as long as the condition is satisfied, we are going to execute Plan A multiple times again and again, only when the condition is false, we will get out of this looping and go to next part of the program. That is called while loop. Because we say while the condition is tested to be true, we can close the statements will be executed. In terms of the syntax, the while loop has a while as a keyword and has the condition and has a colon and then has some statements. It is also quite similar to the if statements. Only difference is now, we use while, instead of if. The first line known as the while clause and it specifies the condition. When the condition is true, we will keep running on and while condition is false, we get out of the while loop and we need to have the colon there to indicate that this is a while clause. The assessments will be, the parts in a reputation loop will be executed again and again. Again, you must have a indention to indicate that this is our part of the while condition. It is in the plan A part. Only when the condition is true, we are going to execute. If the condition turns to be false, then we're going to skip and then move to the next part of the program. Let's practice in our colab, for example, we can print all the integers up to 10. To do that, we can set up our initial, let's just print out all positive integers up to 10. Let's say X equal to 0, which is our first integer to print, while X less and equal to 10, which is our condition. We should not print X anymore. For this very simple while loop, we have a initial condition. We have, while X less and equal to 10, we're going to print X. However, here will be a critical or fatal mistake, which means now, we see X is 0 and we compare 0 with 10, we print 0 out. Then again, we compare 0 with 10, we print 0 out. Lastly this will be a infinite loop because the X will always be 00, will always be less than 10. The condition will always be satisfied, so the loop will always running without it. It is important for you to remember to have some change of the condition in a while loop. When the change accumulates to a certain point, you are going to end this loop. Here what we need to do have the change is X equal to X plus 1. That is for every X printing out, we're going to increment X by 1, so we're going to print out 0, 1, 2 up to 10. For X equal to X plus 1, there is a shorthand right, for this statement, which is X plus equal to 1. If you want you to show off you're familiar with Python shorthand, you can write down this as well. Let's execute this code. As we predicted, well as we expected, we print out 0, 1, 2 up to 10 as we print. How about we do another small task, print all integers from 10-0. This time we need to print it in a reverse the order from least to greatest, but from 10-0. Actually using a while loop, it is still very simple to do so. Let's set up our initial condition, as while X equal to 10. While, X is bigger than an equal to 0, which is our end condition, we're going to print X. Again, remember to modify or to update the X in the loop, otherwise it will be even into looping. Here, we need to have X minus equal to one, which is the same as x equal to x minus 1. Every time we print out the X, we're going to decrement X by one. Let's execute this part and we see that 10, 9, 8, 7 up to 0 will be printed out. We just dealt with some numbers. Let's do another very commonly seen while loop. That is the input validation. A lot of times, for example, we have to enter a password so we can get into a system and those password will be compared with some preset out keywords by you, a long time ago. Only way the two strings, the input and the saved keywords, matched the system of our nature in otherwise, you will be asking to enter the input again. This is a simple input validation or password checking process. Let's say we have our password on record is secret. This one is the one saved in the system and we are going to ask for the user to enter a password. We're going to say password you entered is equal to input please enter your password. Now we have to string one is the one saved in the system as secret only we know that and the other one is the password entered by a user, maybe a hacker. We're going to compare these two and whenever it is a match, we're going to let the user in and say bingo or welcome. If it is not, we're going to keep asking the user to enter the password. So we're going to paste that while pass word entered is the same as passwords record. When this is a not match, we are going to ask again. I'm going to copy this part down here. Lets the user know wrong password. Please enter again. Here is where I will change the condition. I have the password on record as secret and I did want inputs before I go to the while loop. I compare them, if only when entered password is not matched by the passwords on record, we're going to ask the user to enter the password again. If it is still not matched, the user have to enter again. Only when the password entered is the same as the password on record. Well, going to printout bingo welcome. That will be a very simple input checking, validation, and it's run a program to see how it looks like. Please enter your password. We know it is a secret, but I'm not going to try that before. Let's say, password. It is wrong. Let's try, wrong. Still wrong. Let's try again. Again, still wrong. Let's try something else. As long as we are not entering the accurate password on record, we are not going to get out of this while loop. You can see that the program is keep running, waiting for your input. Let's try something similar, not exactly. Let's try capitalize secret. Before I enter it, you can make a guess, whether or not this will be the right password. The answer will be, no, because you learned that Python is sensitive of the case, or string is case-sensitive. Capitalize S secret is a different string of lowercase s secret. We can only enter all lowercase secret, and gave the bingo and a welcome printed on the screen. That is the while loop of during the input validation. Another important and interesting implementation of while loop is to use a flag. The flag basically means when we raise the flag, we are going to do something. If we put the flag down, we're going to give up something, and it depends on whether or not the flag is on or off, we can repeatedly do the task. Here, we are going to write a program and we'll keep running and running for something, only when the user entered stop, we are going to exit a program. It will be similar to our input validation, but now we explicitly using a flag. The most of time, the flag will be a Boolean value because while condition or condition will eventually be turned into a pool. The flag itself can be either true or false at the beginning. Let's say, flag is to true and while flag. If we do not change the flag, this will be an infinite loop, while true and running forever. Let's say inputs is equal to input please enter some words to display, and enter STOP to fix it. Again, we assume our user will be super friendly and cooperative with us. So only the user will enter all kinds of words to display on a screen and enter all capitalized S-T-O-P to exit our program. We are going to do a check if inputs equal to STOP. Now you know what I'm going to do. This is the situation when the user tell us I want to exit your program. Here, we have to change the flag to false, so that for next run we're not go to print anything else. We're going to print out inputs, no matter what. Let's run this program. Instruction, please introduce some words, so let's say, "Hello World. I love Python." Basically, the program will run forever, and if we have in lowercase stop, now off you should know this will not stop, only when we enter S-T-O-P, all capitalized. It will print out and it will eventually stop the looping. This is another application, and it is an integration of the flag and the while, which is widely used in our practice. Let's go back to our slides. Now you can, again, play in our Colab. You can download Module 4, Lab 1 at Python Notebook. You can finish all the small tasks there and again, you can ask for help on discussion board. I'll see you back later on.