 So now we look into the next control flow mechanism in programming and this is known as loops The idea behind a loop is let's say for example I've decided to be just a terrible terrible instructor and I told you your homework assignment was to print mr. Gowita is awesome 100 times Yes concede. Yes. I am whatever So what would happen is, you know, you'd probably look at anything You'd start to get a really good feel for a copy and paste You know, you'd highlight the code and then you'd control C and then you control V and you'd highlight that again Now you have two lines control C control V and you do this a few times and then you'd eventually hit You know about 128 and then you delete 28. You're like, ah, all right done deal That's pretty annoying, you know, I'm a lazy program. I don't like to do things more than once So how can we tackle this issue? And this is actually where we bring in the idea of a loop So how's a loop work? Pretty much it acts the same way as when we looked at the if statement if we think about the if statement for a second. I wrote if Some conditional Right here, and then I put code inside here and I executed that if this was true only if this was true The same kind of concept actually comes in with my while loop if we take a look here Instead of saying if I've now replaced that key word with while Again, this is a special word that Java knows and it understands. Oh, all right Well, if I see this while loop Then right beside it inside the parentheses is going to be a conditional statement If this conditional statement is true Execute all the code in between these curly braces and you'll see it continues to do this Now when it as you can kind of see with this little flowchart t-thing here once it's done the code It actually goes back up. It actually goes back to the top and Reassesses that while loop conditional so in this case In't I equals zero. All right. I While I is less than a hundred I is zero. So that right now is Zero That's true. So we do a system dot out dot print line Mr. Gweed is awesome. I Plus plus we increment I we make I suddenly become One so then we do the while loop again, we reassess the while loop is I again this time One true Yes, it is or it is I Which equals one less than 100 is that true? Yes, it is we execute this line of code again So we then do system dot out dot print line. Mr. Gweed is awesome. I plus plus again We increment I I now becomes two and We go and reassess the conditional loop a second time we go is two less than a hundred We continue to do this over and over again because as you can see what it allows us to do is take some task and Repeatedly do it So we kind of take a look at that same sort of structure the entire time So one of the things that we can do an idea of what we can do with this is we can actually use this I This I right here and we can design our loops to work in conjunction with this It's not just say a counter say for example. I want to just take all the numbers from One to a hundred and add them together, you know, I got one two three four five dot dot dot 99 100 I got a bunch of numbers. I got to go through oh Okay, how do I tackle this problem again? I don't want to have to write my code and have plus, you know some plus plus All the time are plus equals one plus equal to plus equal to I don't want to do those things I'm lazy. I want to be able to write it in one or two lines if possible and that's what we see here again We have set up Sort of this is known as My running Total and that's exactly what it does is it's just a running total and I go alright Well, you know, then here's my counter counter and while my counter is less than my kind of Condition I go and I say alright. Well, what I do Reassess what some is and then increment my counter So some right now is zero. So zero plus I I right now is one So all of a sudden some Some just to draw it out here some becomes one Increment I so I went from one to two We go back up to the top and we do this again and we'll see that alright. Well, this is now a one This is now a two and we say alright. Well Add these two numbers together one plus two that becomes three Some now is three I Get incremented so I goes from two To three and one more time just to reinforce that we look at it some again is now three I is three add those together some becomes six I Becomes four we continue to do this a hundred times up until the point where we eventually get That number whatever that number is it's a big number obviously as you can tell But this is where loops can tackle us or let us tackle a problem that is a little bit more Difficult because it it runs so big