#include <iostream>
using namespace std;
int main (void) {
cout << " 1\t2\t3\t4\t5\t6\t7\t8\t9" << endl << "" << endl;
for (int c = 1; c < 10; c++) {
cout << c << "| ";
for (int i = 1; i < 10; i++) {
cout << i * c << '\t';
}
cout << endl;
}
return 0;
}
Hey so this code produces a times table…I found it on Google Code’s C++ class online…I’m confused about why “i” in the second for loop resets to 1 every time you go through that loop…or is it being declared again in the first parameter?
Thanks in advance!
It “reverts” to 1 because you explicitly set it to 1 as the start condition of the loop…
The “i” name does not exist outside this loop, so each time this loop is run (for each iteration of ‘c’), then “i” is a new variable, set to a start of 1.