Section 3.3.1 - While Loops. Reminder: you need a full program framework

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.

1 Like


Thanks a lot for the suggested correction. It will be deployed in the next notebooks update :wink: