 In this module, we are talking about our last control structure known as looping. The entire idea behind loops is if we think about code we've seen so far. The first approach that we talked about was sort of this sequential pattern, where say for example, x is equal to 4, y is equal to 5, and then z is equal to x plus y. This entire approach is very sequential in manner. I do n instruction, I move on to the next instruction, and then I move on to the next instruction. And so on, and so on. Then last module we talked about this idea of maybe I have some sets of instructions and I want to still go through them, but now I am in sort of this forking path where I happen to have two potential steps that I could work off of, a true step or a false step. And depending on what happens here, I've now created two branches of my code, and my code can sort of follow those directions. The last design we can think about now is this idea of, as you see in the, as is underlined, this idea of a loop. Now let's imagine that I do have some sequence of code that I need to go through. But I might want to repeat that sequence again and again and again for whatever reason. And so we can imagine that not only do we have sort of our lines and our nice little arrows going to these circles, but I might have a line actually going back up my code. Because again, we're thinking about this in the idea of a loop. I want to repeat, say, this little square, this circle right here. And so another great example of this. Let's imagine your homework for this week is you have to print Mr. Garuda is awesome 100 times, right? You know, that's how we learned how to write in grade school. So it must be good here. No, you know, and obviously, you know, you'll trick it and you'll do like copy and pasting and whatnot. Well, the entire issue here is obviously, as you can see, writing that out multiple times can become a problem because what happens if I also said you had to add in like, you know, the number of the lines that this had to be say one, Mr. Garuda is awesome to Mr. Garuda is awesome 100 Mr. Garuda is awesome. Again, that entire process would become taxing and unnecessary. And as I make changes, you have to modify all 100 lines of code. So as you can sort of imagine, kind of annoying, right? So we could use the idea of a loop to sort of shorten this. And so here is effectively how to solve that homework assignment without making 100 lines. And the entire idea is we can imagine that say, for example, this I variable is something known as a stepper. The sole job of this variable is to effectively keep track of how many times we've printed Mr. Garuda is awesome. And so as you can see, then we get into sort of the while loop. This first little portion here is the key word. Just like when we were looking at functions, we had def. And then when we were looking at conditionals, we had if loops very same, they have while, and then they have a conditional. The entire idea to that conditional is once again, asking two simple questions. Is this a true or false statement? If it is true, repeat the loop. If this statement is true, do everything inside of our looping structure. However, if it is false, exit the, that's a two, exit the loop. So once for our case, we've done it 100 times. Then we run into a situation where, all right, I is 100. I is no longer less than 100 because that's 100 less than 100 is a false statement. Our while loop skips over our code and just moves on as necessary. So again, just to see that we work off of the idea of a loop, a while key word, and then some conditional. And the conditional can be just a single statement or some compound conditional statement, like using ands and ors or nots the things we saw in the past. And then you just put inside of there, whatever you want to be your looped instruction. A great way to think about this is let's visualize a very simple loop. I have once again a stepper variable that is, again, just going to keep track of how many times I've run through my loop. So again, y is going to be zero and zero is less than four. That is a true statement. So we go through the loop and you can see that the little circle in the circle is just ran through and is back to where it started. That's the very more specific point. It's right back where it started and it's going to ask that question again. Well, is y at this point now less than four? Well, after that first iteration, we see that y is now equal to one and y is less than four. So it goes through the loop again. And so that iteration happens. And once again, y is two. So we ask that question again, is y less than four? Two is less than four. So we move through it again. Y is now three. Just to follow my pattern here, y is now three. Is y less than four? Yes, it is. We go through a final jump. And when we get to y is four, we're asking that same question. Well, is four less than four? No, it is not. And so we no longer see a true statement. We see the false and we just move on with the rest of our code. So the one thing I've been talking about here is if you might remember, I've sort of brought up the idea of variables and they have different types of roles. Well, in that case, we've been talking about the idea of the stepper role. And so the entire idea again is this is just going to maintain our iteration the entire time. And then as we move through our code, whatever might happen here. So we can imagine that this is whatever code we want. And then again, y is just acting as our stepper. So here's a great example of a while loop. Something simple as a running total. So just to kind of visualize this from our math world again, let's say for example, I had a Sigma and in is going to equal one and we want this to run 100 times all the entire and then in there we are. The entire idea here is as in increments, I want to add that to our running total. So I happen to have some variable called some and its sole job is not to keep track of my loop, but instead act as a running total. I is my stepper. So again, it's just its job is to keep track of loop. So again, as you can see, I is going to constantly be the variable that is evaluated. The while loop has a section that is going to increment I every single time. So we're just keeping track, but some as we can see here is going to basically accumulate or act as that running total. So I starts at one. So you can imagine that some is zero plus one, then some is going to be plus two, then plus three, then plus forward, etc, etc, until we reach effectively 99 plus 100. And then when we're done, well, okay, this is just printing I but as you can imagine, I could also have printed just to fix this up some. And so again, there is your basic understanding of loops.