Hi! In this video clip, let me explain "Advanced use of while and for loops". For-loops continue until there's some elements remaining in a sequence. So, all elements are used up then for loop stops there. While-loop continues as long as a condition is true. So, what if you want to terminate in the middle of a for loop, or while loop? You use brake and continue. Those two commands are used with if-clause. Why? Because break will be activated when a condition is met. Continue is also activated when a condition is met. So, two commands are used with a if-clause. So, when a condition is met, if the brake is activated, then the loop stops there, immediately stops there. What about if-clause is satisfied and at this time continue command is activated? Then only that loop is skipped. But after skipping that loop, a specific loop, the remaining loops continue. That's why it is called "continue". Also, "else" here. Else statement can be used with while- and for-loop. Else is activated only when while and for loop ended. So, what if, in the middle, the loops are terminated by break? In that case, else will not be activated. That is the use of "else". Now, let me give you an examples of terminating loops. Here is a while loop, which is also used in the previous video clip. Now, we are printing sequential numbers from 10. So, if you execute this cell, what do you see? There is no break or continue. So this is just the usual while loop. As a long as "l" is greater than zero, the loop continuous and printing continues because the printing is based on while loop. So from 9 to 0, numbers are printed. And because this, the last print statement is also inserted in this cell. That's why finally "loop ended at 0" is also printed because that is the last number of "l". Now, here's a case of break use. So, this is the same while loop, if "l" is equal to "5" break command is activated. It means that while loop end there. So, "10, 9," no, no "9, 8, 7, 6" will be printed. Right? So, if we execute "9, 8, 7, 6" printed ,and the final value of "l" is five. Here's another use of while loop using the continue command. So, this is the same, almost the same as the one before we used. So if-statement is the same when "l" is equal five, it continues. It means that only that loop is stopped there when there's continue is activated. But after skipping that loop, the remaining loop, the remaining loop continues. It means that only one element is not printed. Right? So, "9, 8, 7, 6". Five is skipped because this printed is ineffective when continue is activated. That's why five is not printed. And the ending value of "l" is "0". The remaining group continued until the while condition is true. Now, else statement is used with a while loop, which is the same as before. So, let's activate this one, this cell. If we execute this cell, simply the one we used before. So from nine to zero is printed and the last valuable of "l" is zero. But what if there's break in the middle? Then it means that while loop is terminated when break is activated. So, else statement at this time, it's not printed, not at all. So, "9, 8, 7, 6" is printed. Now let me give you the last example of iteration. At this time, a string is used as a sequence in a for-loop. Right? "i" take each character within this string "PracticalPythonforAIcoding". It takes one element from the sequence until the elements, all elements are used. So this is what we get. There is an empty space between letters because I inserted an empty space using this. What if I deleted that empty space? Then exactly the same printing is done. But in order to increase the readability, we can put an empty space, then an empty space is inserted between characters. Now in a for-loop, we are using break. So what is the meaning of this break command? If "i" is a English letter "o" then the loop terminates there. So where is the first "o"? Here "Python". It means that "PracticalPy...th", those parts of a string will be printed. So the remaining string is simply sliced. So, this is what we get. Rigth?. The another one is continue we are using continue. But if a character is "n", "n" character are all screened out. How many "n" in the string? Here's one "Python" "n", and "coding" has "n". And so, two "n's" will be screened out and what you get is this one. From the printed characters, you cannot find "n" because whenever "n" appears, loop stops there, that loop stops there. And then the remaining loop continuous. And if there's another "n" appears, it stops there also. So, I introduced how we "brake" and "continue" in while- and for-loops. Before closing this video clip, let me give you a review question. True or False: break and continue must be used with if-clause. True why? Because when a certain condition is satisfied, the break or continue command will be activated. It means that break and continue need to be used with if-clause. So, the answer is True.