 What's up guys? Root from NullShell.com here today bringing back some more Python tutorials. Oh man. Today we're checking out some looping keywords like break and continue. And these are really interesting. When you're looping with like a for or while, sometimes you might need to manipulate the sort of repetition or the process that your program is going through. And these can be structured with keywords like continue or break. So let's open up idle and I'll show you what I mean. I'll drag it right on over here. Get ourselves started with a new program, a new window. See if this is a filed up Python for the moment. Get a shebang line going on. And here we go. I'm going to do a, I'm going to sort of for loop for I in range, let's say 25. And that's a good number. You know that's a nice number. I like the curves that they've got going on there. All right. So for I in range 25, let's print out. We are at number. And then we'll concatenate the string value of I. We can run this with a five and it looks pretty good. We get a full lengthy piece of idle here. We got go from number zero and from number 24. Okay. That works. So now just kind of like how the return keyword is exclusive to functions. The break and continue keywords are exclusive to loops. So if we typed in break outside of a loop, it give us an error. Let me show you this here. Syntax error. There's an error in your program, break outside of a loop. And this works the exact same way for continue. I'm thinking. Let's give it a go. There's an error in your program. Continue is not properly in a loop. Now this works the same way as return too. I don't think I ever showed you that, but if you're using return outside of a function, it yells at you too. There's a temper tantrum. There's an error in your program. Return is outside of a function. So you're able to piece things together at this point, I'm sure. But just a side note in case you guys didn't actually figure that out. But this is the case here. While we're looping, we can test. We can use our if conditional statements. You can test what i is equal to. Let's say if i is equal to 20. Then we'll create a new code block here. If i is equal to 20, let's continue. So now what continue is going to do is anything after the keyword inside the loop will be skipped and it will continue to the next iteration. So it won't display 20 when it's running this. It'll go from we're at number 19 and then it'll go right to we're at number 21 because 20 has been skipped. So let's try it. We're at number, let's start at the top first of all. We're at number 0, 1, 2, 3, 4, 5, 6 and it continues. And when we get to 19, you don't see 20 here because we've continued. We have gone to the next iteration without even considering what's after. And let's try this for things that are factors of 2. Yeah, I think. I mean if they're divisible by 2. So let's try it. We got... Okay, so it's looking at odd numbers here. That's kind of interesting. We're at number 1, we're at number 3, we're at number 5, we're at number 7, we're at number 9. So it's not going to display anything that is an even number. So what if we took a look at the other keyword now? What if we tested if i was equal to 20? First of all, I'll show you what this does without this entire thing. And we can use a little bit of our comments magic that we learned in a few videos back. Okay. If we completely disregard this, we can have it go through 0 all the way to 25. But what if we do if i is equal to 20 and we break, what break will do is literally break out of the loop. It will stop testing it completely. So let's print program has started. I'm going to give ourselves a little bit of a notification when we're looping and when we're not looping. And we'll put a little bit of a tab here just like we did in the previous tutorial so it looks kind of fancy. So let's see how this works without our little break keyword, first of all. If we do a f5, program has started, program has ended. Okay, slick. So now let's test if i is equal to 20, let's break the loop. Let's stop counting. We go from 0 and keep counting up every now and again all the way to 19 and then we stop. So now we can look at this in an interesting way. We can print i ended at, we can catenate on the string value of i. i ended at 20 because we've broken out of the loop. But if we don't have this, it'll end at 24 just the way it should. Now what if we continue to go back to our, if i divided by, if the remainder of 2 is equal to 0, we can continue. We can still have this and we'll have all these 13579, but it's still going to get to 24 even though it's only displaying 23. Because the number is still being counted, it's just not being displayed because we're skipping that iteration with the continue keyword. So when you look at these two in conjunction, continue and break, you can do some pretty interesting stuff to your loops. And this doesn't have to be with a for loop. You could use a while loop. While, let's get some variables here. Count equals 20, limit equals, if I can type things correctly, limit equals 25. While, counter is less than limit. You can kill the for loop. Now we have this exact same thing. Okay, program has started. Oh, we have to add it. Oh, let me uh, uh-oh, uh-oh. Gotta kill Python before it comes to, before it comes to hurt us. Peek-Kill, Peek-Kill Python, here we go. Holy mother of God, Peek-Kill Idol. Oh, this is an emergency kids. Oh man. Alright. See, this is why you should always, always add to your while loops. So you don't get stuck in an infinite loop and have your computer start crying and like, wet itself. But I think you guys understand what I've been trying to get at here despite these little mishaps. If you were to do this with the while keyword, you can still have that exact same, um, let's see, output. You can use those keywords in either the while loop or the for loop. You can use continue and break and they have the same functionality. They do the same thing. So uh, thank you guys for watching though. Thank you for uh, for sticking with me even though I had a little bit of a mishap here at the end. It's a little embarrassing though to have my computer piss its pants. But hey, uh, that's what programming can do to you if you don't do it correctly and you don't pay attention to what you're doing. So don't ever, don't ever listen to me. But all thank you guys for watching. If you could give me a like, maybe a comment, maybe, maybe favorite, maybe subscribe. I don't know, just, just uh, just some ideas, just some uh, just some ideas. Have a great day guys. Goodbye.