JAVASCRIPT · ОСНОВЫ · LESSON 10

Repeat the meter.

for loop · about 12 minutes

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

Several steps.

for repeats the code. At first, step is 1 and then grows 1 to the border.

for (let step = 1; step <= 3; step++) {
  console.log(step);
}

✦ There will be 1, 2, 3.

STEP 2

Don't forget the border.

Знак <= разрешает взять число на границе. Если поставить <, последнее число не попадёт в цикл.

for (let step = 1; step < 3; step++) {
  console.log(step);
}

✦ Only 1 and 2 will appear here.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check the names, brackets and signs.

for (let step = 1; step <= 3; step++) {
  console.log(step);
}
Open the editor for class work
HOMEWORK

Solve it yourself

Using for with the step variable, output numbers from 1 to 4 inclusive.

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

Opening up your homework