In the following program, a nested loop is used to check how often the loops are run through.
#include <iostream>
using namespace std;
int main() {
int a = 6, b = 8, c1 = 0, c2 = 0;
for (int i = 10; i > a; i--) {
c1++;
for (int j = 0; j < b; j++) {
c2++;
if (i == j) {
cout << "How many times the loops are run?" << endl;
cout << "first loop: " << c1 << "\nsecond loop: "
<< c2 << " (" << c1 << " * " << b << ")\n" << endl;
}
}
}
return 0;
}
How many times the loops are run?
first loop: 4
second loop: 32 (4 * 8)