For loops

Loops repeat sections of code.

For loops are best for situations where you know exactly how many times you want to loop your code in advance, like coding a triple jump in a game. Nested for loops are often used to print game maps to a screen.

In C++, for loops have three parts; a start point, an end point, and a counter:



In this example, the loop starts at 0, continues to loop as long as i is less than 10, and because the "++" operator means "add one" this loop counts up by 1's. This loop prints out the numbers 0-9.

Here are some other examples of for loops:

Nested Loops
Nested loops are loops inside other loops. In game programming, they are particularly useful for printing out grid-based levels and maps. Here's a basic example of what one looks like: