 Hey, what's going on guys root from no shell.com here today, and we are looking at some more Python Continuing off our Python tutorial video series that we've been doing we are on lesson 19 at this point And now we're gonna start looking at loops now loops are really special What they do is they let you repeat a sort of process or a code block as many times as you need to and you can pass in Different values and different different information so you can manipulate things over and over and over again and yet you can still test for Different scenario is depending on the values so there are usually Different kinds of loops in this case We're gonna be looking at the for loops and the while loops and maybe some more some come to mind But I'm pretty sure that's really all we have to worry about for now But we're gonna check out while loops in this video So I'm gonna get started with idle you can open it up to and I'm gonna drag it over here So it's visible create a new window with control and I will save this as file dot Python You can save it whatever you want store. I kind of suggest you save things Like save each lesson individually so you'll have something to review if you want to you can comment things that you've kept in mind or things You've noticed and that sort of thing so you can almost have like sort of notes while you're going through these video series But hey, let's get started um in my case I'm going to get started with the syntax So you can look over on the left-hand side there the while loop has a sort of syntax where you just have Keyword while you have your condition and then you have your colon and then you have your new code block Which is just indented I'm gonna throw in my my my programming style here I'm gonna have my condition surrounded in parentheses So I'm gonna leave that blank for now finish up the skeleton get my colon going get my commented commented code blocks here and here we'll we'll type in our code and the condition now while loops the condition will always Evaluate to one or one or another boolean value. It'll be either true or false If it's false, it'll stop repeating this. It won't it just won't do it kind of like an if statement If it's true, it'll do it again and again and again and again So we can Potentially put ourselves in an infinite loop if we just said while true Which is obviously already evaluated to true. It'll just repeat this same thing over and over and over again I don't recommend doing this for too long. You might get it like a segmentation fault or something Probably not really good for your computer or anything, but you can just you can do something. Let's print out. Oh my god And I'm gonna put a comma here rather than a colon a Comma is actually going to prevent print from outputting a new line So that's a little bit of an interesting technique and attack that you can keep in mind and let's try this Let's run this program. This is gonna. This is gonna be a little crazy when you look at idle Oh god, oh god, oh god, oh god, oh god. See it's gonna keep doing it over and over and over again We can hit ctrl-c here to stop the process and I'll switch right back over here, but it's it's gonna keep doing this There's nothing stopping it But let's say we tried something with a with a variable. Let's give a counter. Let's say counter equals zero Now we can have a different condition say Counter If I can type things correctly counter is less than Let's actually set a new another variable here limit can equal 10 So counter while counter is less than limit print We are counting Now watch this very closely because if we if we try this it's gonna do it Repeatedly it's not gonna stop and the reason this is is because we haven't Incremented a counter now counter is what we're going to keep adding values to and Incrementing is the terminology that we use here we add one to and that's what incrementing is really meaning We're adding to the value just bit by bit. So if we do counter Plus equals one now keep in mind that counter plus equals one is the same exact thing as counter equals counter plus one We're taking the value We're taking the current value of counter and then adding one to it and then resetting the counter variable to that So when we have that assignment operator with the plus equals all that's really doing is taking the current value and adding more to it It's it's taking the relative amount So if we are counting we can we can try this now and now we get we are counting we are counting we are counting We are counting and it does this ten times Because we have zero and it's gonna go while it's less than ten so it's gonna go zero one two three four five six seven eight nine But it's not gonna get to ten because it it doesn't want to equal ten it wants to be less than ten now We can check this out in the program. We can just say we are counting We're counting at and then we can concatenate the string form of counter Let's try it again. We are counting at zero one two three four five six seven eight nine It doesn't get to ten So once it gets there, it'll stop though. So if we give ourselves a little bit of a notification of what's going on Program starts Delete that here get to the end of the line Program ends Let's get a new line here. So it's a little bit better looking Program starts we're counting all these things and program ends. Okay, so this makes sense because it's going to continue It's gonna keep repeating this code Until that condition is returned false because once counter gets to ten It's it's not less than ten anymore. It's it's greater than ten. It's equal to ten even so if we get out of there And we print counter Let's do the string the value of counter we can concatenate on there is not less than The string value of the limits Now we can run this ten counter is not less than ten and that makes sense Counter has added once again, even though it's nine Because it's gonna keep doing this counter First it's gonna run through counter is equal to zero and it's less than ten So it does this it adds to it again It does it it goes now that it's one it does it again one is less than ten keeps doing it two Two is less than ten does it again what eventually it's gonna keep doing this until it gets to the point We're nine you have nine nine is less than ten So it's going to add to it and ten now we now counter is it ten But ten is not less than ten So we have here Counter has become ten, but it's not gonna run this again because our expression has returned false. Does that make sense? I feel like that's all I want to try for now in this video. I hope you guys enjoyed this I hope it was able to understand I feel like it's a little bit of an easy concept and Especially when you keep exploring it in this sort of way you can see lots of things It all it matters really is whether the expression or the condition that you are testing for returns true or false So there you go. See you guys in the next tutorial and have a great day