This is a sample program out of a book I have (C++), demonstrating the use of the "continue" statement, in a FOR LOOP. The program asks you how many "items" you want to buy and charges 3 dollars per item, but the 13th item is free. For example, if you enter that you want 12 items, you'll be charged 36 dollars. If you enter that you want 13 items, you're still charged only 36 dollars. When you enter "14" the "total" begins to increment again, and you would be charged $ 39 in that case. (Every 13th item is free)
Where I get confused is the use of the "total +=3;" statement.. I just don't get how exactly it works
#include <iostream>
using namespace std;
int main(void)
{
int num;
int counter;
int total = 0;
cout << "How many items do you want to buy: ";
cin >> num;
for (int counter = 1; counter <= num; counter++)
{
if (counter % 13 == 0)
continue;
total += 3;
}
cout << "Total for " << num << " items is $ " << total << "\n";
return 0;
}