Even though the while type of construct is very useful in a wide variety of situations, another iterative structure, the for statement, can be used to iterate across a range of values easily. A for statement allows us to write a loop that is executed a specific number of times.
The code will use cout five times. The value of the variable i will start at 0 and go through the full sequence of values 0,1,2,3,4. This value is then squared and printed.