Please enable JavaScript to use CodeHS

Loops in C++

By David Burnham

Notice the declaration has 3 parts to it. The first part, `int i = 0`, creates and initializes our loop variable. This variable can be used in our code block if needed. The second part checks the condition, in this case `i < 5`. As long as our loop variable is less than 5 at the start of our loop, our program will execute the entire code block. Finally, we see our incrementer, `i++`. This gets executed after each loop, but before the condition check. In this case, our loop variable `i` will get incremented by one each time we run the loop. So how many times will this loop run? Try it out and see if you are correct! ">