I tried compiling the snippet provided to test the for loop, and got a couple of errors (specifically error: expected unqualified-id before 'while'
and error: 'cout' does not name a type
. I realized the example code didn’t have the full program structure. The full program should look something like:
#include <iostream>
using namespace std;
int main() {
int counter = 0;
while (counter < 5) {
counter += 1;
cout << "Count: " << counter << endl;
}
cout << " Got out of the while loop!" << endl;
return 0;
}
Hope this helps futures students.
/K