Welcome back to Introduction to Visual Basic. This is the second course in the Introduction to Computer Programming with Visual Basic specialization. We're actually in our fourth module and we're going talk about iteration. In this module we'll learn how to change the flow of a program's execution to repeat code. In the last module, we talked about decision branching, where we used 'if tests 'or 'select statements' to selectively decide which pathway to flow based on a test. Here we want to do the same code repeatedly. Sit back, relax, let's have some fun. Some learning objectives; upon completion of this module, I want you to be able to develop programs that utilize for loops, you should also be able to develop programs that utilize do loops, and lastly, you should be able to develop programs that utilize exit and continue statements. This first lesson we'll talk about the for/next statement, again, we're going to use the for next statement to change the flow of our programs to repeatedly execute some section of code. The syntax looks like this; we're going to say For and we're going to have some counter variable, and we can specify the type is going to be equal to start to end, and then we can specify how to step, if we don't specify the step, it will be by one. It will move from the value start will be the first iteration and it will increment by one if we don't specify steps until we get to the end, and then we end the block with the next, and we can say what the name of the counter is, so it's a little more readable, but that's optional, and any statements between that for and that next are repeated. Basically if step is one, end minus start times plus one. Let's take a look at an example. Here's an example, we're going to basically add up the numbers one through five, so you see we've got a variable i, I'm defining that as an integer, and I'm going to set it equal to one to start, and it's going to go to five. This means we're actually going to run the code between the for and the next, five times. The first time i will be equal to one, the second time i will be equal to two, the third time i will be equal to three, you're probably getting this now, the fourth time i will be equal to four, and the fifth time i will be equal to five. I is going to move from one to five, I didn't specify the step, that means it's stepping by one. What I'm doing is I'm accumulating a value, so you'll see I declared another integer sum, and by default it's going to initialize to zero and the plus equals says, take whatever is in sum, add, what's on the right-hand side, which is i and assign it back to sum, so after one iteration, sum will be one, after two iterations, sum will be three, after three iterations, sum will be six, you start to get it. Here's an example where we changed the step. In this example we're going to go from one to nine, the rest of the code is the same, so the first time i will be one, the next time i will be three, then it'll be five, then it'll be seven, then it'll be nine. Same thing we were to accumulate the summation of i as we're doing so. This example, we're actually going to go backwards, we're going to start with nine and we're going to step down to one using a minus two each time. If you modify the step, you can go in a different direction. I will first be nine in our first iteration, then it'll be seven, then five, then three, then one. A little review here: A counter variable is incremented or decremented in the four next statement. It's incremented by default, but if you change the step to be a minus, it will decrement it. That step clause allows you to adjust how the counter variables change in each iteration. The for next statement can be used to accumulate a value, that we saw there in the other different examples. I'll see you in the next lesson.