How does it cycle through 5 numbers I still dont get it |
const int numsToCalculate = 5;
for (int counter = 0; counter < numsToCalculate; ++counter)
this loop does these values of counter: {0, 1, 2, 3, 4 } if you count them, there are 5 numbers in there. When counter reaches 5, it is no longer LESS THAN 5 (nums to calculate is 5) so it stops. ++ means add 1 every time through the loop. you can put anything in there, you can say += 3 and it would do 0, 3, and stop because 6 is not < 5 again.
int declares a variable. Creates may be a better word to get you started. You only need to 'create' something one time, after that, you have it available to use.
It seems like you jumped right into a fairly complex problem with no background. You may need to back up and do a few very simple programs first. First understand what a variable is and how to use it, and how to write a simple loop like printing 0-10, work your way up. And, can't say it enough times, the code you found is a slightly odd way of doing the problem anyway.