Hi, everyone. In this video clip, we are studying "while" control statement or "while-loop". While-statement is used in order to control arbitrary number of repetitions. "for-loop" is used for when the number of repetitions is already known. While loop is used for arbitrary number of repetitions. So, iteration is going on until a condition remains true. That is the characteristic or definition of while statement. Sentinel-controlled loop is also used in while statement. Sentinel, another name of sentinel, is flag or signal. So when a sign appears, loop stop there. That is sentinel or signal controlled loop. As I said before, while loop is used for undetermined repetition. When a condition is true, it goes on and on without stopping. One example here I give you is calculating powers of 3. "k=1", a variable "k" is announced, and initial value one is assigned to that "k" variable. While "K" is, less than or equal to 100, the following sentence will be repeated. The following sentence is "k = k*3", "k*3". So when one number, number one, is inserted in this control statement, "k" is less than 100. Obviously, one is assigned to "k" so it becomes one time three means 3, 3 is assigned to "k". So, the value assigned to "k" is updated from 1 to 3, and 3 will be printed here. And then three is inserted here. 3 is less than or equal to 100. It means that the condition is still true. Then three is used for another calculation. Then it becomes 9. Nine is assigned to "k", nine is compared to 100. Still the condition is true. Nine comes down here, and it becomes 27. 27 is assigned to "k". "k" value is again updated, then 27 will be printed. Keep repeating this process. As long as "k" is less than or equal to 100, the loop going on. But if "k" is greater than 100, it stop there. So, let me execute this code then it writes this way "3, 9, 27, 81, 243". 81 is less than 100, so 81 down here, but multiplied by three. And that value we assign the to "k" and that value printed here. That reaches 243. Now you understand how while loop is working. Let me give you another case. Subtracting one repeatedly, like "l" has initial value of 10. While "l" is greater than 0, the following calculation will be repeated, subtracting by one and assign new value here and printing "l". But at this time in the print sentence, I am adding this parameter "end". "end" equal empty space, one empty space. Then what happens? 9, 8, 7 until 0 is printed. This means that if you use "end" printed horizontally printing horizontally. So the values are printed horizontally, not vertically. In this case, the numbers are printed vertically, right? But in this case, it is horizontally printed. So "end" is a parameter used to control the direction of printing in print command. Now, what about we don't give empty space? Then all numbers are packed consecutively. Continuously they are printed without empty space. By inserting empty space, you are adding an empty space at printing. So, this is nice printing, right? So, another a little bit complex use case of while statement. Two variable are created. "total" variable. Zero is assigned to that variable. For a number of days, we are calculating the average temperature of a week. So seven numbers are collected, and they are stored and average numbers are calculated. But in this calculation, we are using while loop. So "temp1" is a variable. It takes value from input function. Enter temperature here. "Enter temperature or 200 to stop". It means that you type in a temperature, or if you want to stop there, you type 200. It means that here, 200 is a sentinel or a sign or a flag. You are raising a flag. Oh, this is the end. 200 here is sentinel. While "tempe1" variable is not equal to 200, the loop is going on. Right? But we don't know how many loops while are going on? So, total initial value is zero. The first temperature is added and the total temperature is updated. A number of days. Because whenever a loop goes, it means that a number is typed in. And in order to calculate average number, how many days of temperature are collected. You need to count the number of days. So "num_day" initially was zero, but you are adding one whenever there is a loop, you are adding one. So, the total number is increasing. And because "loop" is going on, you need to ask, keep asking "Enter temperature or 200 to stop" the loop. So then probably seven number. After seven numbers typed in, the person typing numbers, temperatures, the person, will type 200 in order to calculate one-week average temperature. So the total variable and number of day variable is calculated. Then, using the information contained into the two variables, you are calculating average. So, if number of days is not zero, it means that if it is zero, no information is typed in. If it is not zero, it means that a certain number of temperature information is provided. So average temperature is calculated based on this formula, total divided by a number of days. Then print "Aggregated temperature is" "total." "the number of days is", "num_day". And then average temperature is avg_temp. Right? So, but in this case, three print statements are shown. But the last one is different from the previous two. Here's "f". After a letter "f'", single quotation mark. You can use either a single quotation mark or a double quotation mark. In between them, you are typing in the whole sentence that you want to print. So one or some are part of that whole sentence is string. But a part of a sentence is not string, within those curly, curly brackets. In curly brackets, "avg_temp" average temperature variable information is inserted, which means that average temperature is not a string. It is number. That's why within curly brackets, you're inserting it. Then that number turns into a string, and the whole string is printed. So that's why this way of presenting information is called a "formatted string". It is a string that is created and printed, but that string has a certain format. That's why it is called formatted string. We are using formatted string a lot in coding because it is very convenient to print an output, neatly and nicely. So average temperature is called in. This is the string and without coma. You are simply adding the information that you want print, but they are not initially numbers or strings. Oh, they are not a string but numbers. But numbers turn into a part of a string. Else means that no number. No temperature information is provided, then "No temperature was entered" this information will be returned. So let us execute this one. Then temperature, what about, we need to type seven numbers, like [typing] 23, 17, 24. 16, 25, 15 and 20? Obviously, you will see the average is 20, right? Then what happens? And seven numbers are typed in, but you need to provide the sentinel in order to stop the loop "200". Then the following lines are executed here, 200 is not added to total temperature. So, the aggregated temperature is "140", the number of days is "7", and average temperature is "20". Ah, everything is done nicely and neatly. Before closing this video clip, let me ask you a review question. True or False: A while loop is useful for an arbitrary number of iterations. True or False? Yes, it is true. For loop, that's what we going to see in the next video clip, is about repeating, iterating the same process in a finite number.