C++ · ОСНОВЫ · LESSON 11

Repeat to the border.

while · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

How it works.

while executes the block as long as the condition is correct. The meter inside needs to be changed.

while (count <= 3) {
    cout << count << endl;
    count++;
}

✦ Without count++, the repetition may not end.

STEP 2

Try to understand.

Without count++, the repetition may not end.

int count = 1;
while (count <= 3) {
    cout << count << endl;
    count++;
}

✦ Compare this to the first one. Then do the cool job yourself.

IN-CLASS PRACTICE

Type the code yourself

Manually type the program from the sample. So you'll remember commands and brackets.

#include <iostream>
using namespace std;

int main() {
    int count = 1;
    while (count <= 3) {
        cout << count << endl;
        count++;
    }
    return 0;
}
Open the editor for class work
HOMEWORK

Solve it yourself

Start with int count = 1. Using while, output numbers from 1 to 4 and enlarge count within the loop.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework