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

Repeat action.

for · about 12 minutes

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

How it works.

for sets the beginning, the boundary and the next step. ++ adds one.

for (int step = 1; step <= 3; step++) {
    cout << step << endl;
}

✦ Если поставить < вместо <=, граница не войдёт в цикл.

STEP 2

Try to understand.

Если поставить < вместо <=, граница не войдёт в цикл.

for (int step = 1; step <= 3; step++) {
    cout << step << endl;
}

✦ 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() {
    for (int step = 1; step <= 3; step++) {
        cout << step << endl;
    }
    return 0;
}
Open the editor for class work
HOMEWORK

Solve it yourself

Loop for with step counter output numbers from 1 to 4 inclusive.

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

Opening up your homework