 Hey everybody, this is Brian and welcome to the sixth Python tutorial. Wow, we're just moving right through these little guys. We're going to call this the very descriptive video six. Today, we'll be covering loops. What's a loop? If you're from other programming languages, you already know. But if you're not, you're not familiar with a loop. Imagine a conversation with a six-year-old child where they say, well, you know, why is the sky blue? And you say, well, because of the way the atmosphere, blah, blah, blah. And they go, why? And you go, well, the way the light reflects off the ionosphere. Well, why? Well, because photons come from the sun and hit the plant. Well, why? Yeah, they just keep asking the same question over and over. That's a loop. Or if you've ever talked to an old person that has just completely forgotten everything. So let's give an example here. We're going to make an empty list. And we're going to do the for loop. And we're going to say, for ion range. And we're going to say 10. Remember your colon there. So we're defining the scope. We're going to say x dot append. And we're just going to append the ion there. And then we're going to print. Actually, let's just print x. Why not? That way we can actually see this list filling up. And there we go. Every time this loop iterates, that's what that's called when it goes from here down to here. It'll actually jump back up. It's called an iteration. It used to be called a go to where you would actually explicitly say go to and then it would jump back. You can see for IE for I in range 10. So we've got 10 things. It's zero based. So the first time it's zero, then zero one, then zero one, two, three. And you can see as it stair steps down, it grows this list. And when it hits the range 10, our upper limit member zero base. So it's actually 10 minus one equals nine. It's going to actually stop. And the execution of that code stops. So we can actually say print finished. Let's run that again so we can see it in action. And yep, there it goes. And then it's finished. So that's a loop. Now if you remember from my previous conversation about scope, we have scope one. And then actually, let me just comment these. That way you can state in the code scope two and scope three. I wanted to kind of explain this a little bit better about scope. Somebody out there is going to say there's not three scopes. There's only two because scope one and scope three are the exact same scope. And that's true. But it comes with the disclaimer. Variables must be defined before they are used. That's why for the purposes of teaching you scope, I broke it up into different scopes. This is technically scope one. The difference being, let's say we want to print and we're going to make a variable called name and actually move it up here. And we want to actually define it down here. We're going to say name equals Brian. What's going to happen? We already get the sense that something bad is going to happen because we got that unresolved reference. But we've defined it here. Let's run it and just see what happens. It says name is not defined. The reason for that, it's a little bit of a gotcha with this language and almost every language. You have to define the variable before it can be used. When we run it, now it will run just fine. See, there's Brian. You can now take this print statement and put it down here and it'll still work. If we take that same print statement and we throw it into our scope two, it'll go every time that is run. That's the difference about scope. Now let's make another variable here and let's call age and we're going to change this and we're going to say print the age. There is the age right there. Now why did that work? We've said that if you define it, it's not allowed. The reason why that works is the way Python treats scope is a little bit different than most languages. My cat just woke up, she's very old and she's deaf so she's just going meow and meow and meow. Anyways, because the scope is considered a subscope of scope one, scope two lives inside of scope one, everything is accessible. There's ways around that we'll cover in future tutorials but I wanted you to really understand how things work. Let's go back to our little example here. There's our for loop in all its glory. Now that you have a better understanding of scope, loops will not be as mysterious. Loops and scope go hand in hand so that you understand exactly what's going on here. Now we're going to make a tuple and we're going to say, we could actually just have kept that but I wanted to just show you for illustrative purposes for i and x. If we're going to print, maybe if I can spell print, I'm going to take my eye medication. I had eye surgery so I no longer have to wear glasses and I love it but I have to take this medication because I'm still healing. My vision gets a little blurry. I would love to blame a lot of my spelling mistakes on that but I just am a horrible speller. So, x. And now we're going to do i-1. Ladies and gentlemen, I think we have an earthquake. Whoa. What the heck? Yeah, honey, I think we had an earthquake. I think we're still having one.