cout << m/3 << endl; //10 / 3 is 3 in integer math. you are going to print 3 numbers, every third one, so you can just directly compute this output. If it were more complicated, you can also add a counter and inside the if of the loop, add 1 to it, at the end, it will tell you how many it counted.