Hi, this is Mike McMillan. And in this lesson, we're going to learn about the first way to perform repetition and see the for loop or the for statement. Let's get started. Let's start out with a syntax template. So the for statement works like this. The first thing we do, and I'm gonna highlight this, on the screen, is init or initialize what I call a loop control variable. And this is going to be a variable that's going to control how many times the loop executes or iterates. Next, we have a condition or relational expression which is going to test the loop control variable to determine when the loop will stop. And then finally, we have a statement that will modify the loop control variable so that we will get the loop to eventually stop. Otherwise, the loop would run forever in an endless loop. Then we have an open curly brace, and then we have the statements, or statement or statements, that we want to execute, and then finally a closing curly brace. So let's start off with a simple example, and let's just print the numbers 1 through 10 to demonstrate how a for loop works. So let me type that up. So here you see, I have the loop control variable, i, which is kind of a standard convention in programming for for loops. I initialize it to 1, my condition or my relational expression is, i less than or equal to 10. So, while i is less than or equal to 10, the loop is going to execute. And then finally my modification is to increment i by 1, i plus, plus. Inside the loop, we print a value of i. And so let's run this program. And there are my numbers 1 through 10. So as i increments from 1 to 10, then the loop executes. When i becomes 11, then our condition becomes false, control jumps to the line after the for loop ends. Let's look at another example. I'll comment this one out also but leave it on the screen. Let say I want to see how much a savings account will increase after 20 years earning 1% interest per year. Savings account, so make a lot of money these days. So we can do that this way. We can start out with a... So let's start out on 10,000. And we can have an interest rate. I'm going to express it like that, rather than multiply by 0.1 and then add the balance back in. We'll just multiply by 1.1 and not have to add the balance back. So then we can have our loop. And understand, I could have also written this statement like so. We haven't had the opportunity to cover all of the different operators that C has but we could also write it that way, but I'll write it the simple way, balance equal balance times rate, just to make that clear. Let's run that program. Actually, let's make one other modification. Let's watch the balance as it grows. And now we'll run that program. And I made one mistake and I'm not going to change it. Again, I could have, but I'm not going to, so that we can see it. I made the mistake of making the balance a decimal number when it's really a floating point number. And also we need a new line for each one there. Let's try that again now. And then we'll see a better result here. There we go. Bring that over where you can see it. So that's what's gonna happen after 10 years at earning, and actually I said 1%, that's 10% interest, but that's fine, you get the idea. Again, my balance is a little bit off because I displayed the balance as a decimal. So let's change that to floating point. Run it again. And there we go, that's better. Last computed value and the ending balance. So to summarize, the way the for loop works is, you have a loop control variable that you initialize, you have a condition that's going to state when the loop will stop, and then you have a modification to increment the loop. Of course I'm doing it by 1, but it could be any modification that you want. You could even count backwards from 20 to 1 with a decrement instead of an increment. But at any rate, there must be some modification. If you leave it out, and I'm gonna end on this little example, if you leave out the modification, it's not a mistake. Well, what's gonna happen is, the program's just going to run forever, or at least till you run out of memory. So that wraps up this lesson on the for statement. And in my next lesson, we're going talk about another way to perform repetition and see the while statement.