 Hey everybody, it's Brian. Today we're going to be discussing loops. There are two basic types of loops, a while loop and a do loop. We'll take the while loop first. Simply type the word while and press control space. That'll pop up in the IntelliSense window. You'll see we have a couple different types of while loops. We're just going to choose the while loop with condition. You see while parentheses condition and then brackets. So that's our code block. Now remember, anything in parentheses is going to get examined first. So what's a condition? Let's just say int x equals 0. And we're going to say while x is less than 10, do something. Well, just for the sake of argument, let's do system. That out, that print line. I'm just going to print the value of x up to the console window. And we are going to just run this and I want to show you what happens. Anybody who's done this sort of thing before knows the mistake I just made. And you see it just keeps going and going and going. Well, we need to stop this program. Why does it just keep going? Well, x is always less than 10. We have to increment x. We'll do x plus plus. That just takes the value of x and increments it by one number. Now when we run this, you'll see that it stopped at 9. Let me actually expand this window a little bit so you can see. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. So it says while x is less than 10, simply print out the value and then increment. That's your basic while loop. And you can do other things like you can say while x is less than or equal to, or while x is not equal to 10. You can do all sorts of things, but that was a mega fail. For that, we're just going to leave it as x less than 10. Now the do loop is similar. Type the word do, control space. And you can see there is a do, your code block, and then a while condition. What's the difference between these two? Well, you may have already guessed with the while loop we are examining the condition first and then executing the code where the do loop we are executing the code and then examining the condition. In other words, in plain English, if you want it to execute once, no matter what, do a do loop. So for this, we're just going to print out the value of x. Going to decrement it. And we're going to say while x is greater than zero. Now we're going to run both of these. And what you're going to see is that it will increment x and then decrement x. And you see, sure enough, zero through 10 and then nine through one. Now, why is it doing that? Let's examine this code real quickly. We've got an integer of x set to zero. We're saying while x is less than 10, we're going to keep incrementing it. Once it hits 10, this condition is no longer true and it will jump down here and execute this statement. Just for clarity sake, let's put in a print line just so you can see what's happening. We're just going to say moving on. That way you can see exactly what's going on here. You see it prints zero through nine and then moving on. And then it goes from 10 to one. So as you can see, it will sit in this code block over and over and over again until this condition is no longer true and then it executes this statement. And then it will execute this once and then it will keep looping through this code block until this condition is no longer true. So that's the while loop and the do loop. Once again, I thank you for watching. I hope you found this video educational and entertaining. Feel free to subscribe to my channel and drop me any questions you got.