feat(curriculum): Add interactive examples to How Do Loops and Iteration Work in JavaScript (#63344)

This commit is contained in:
Giftea ☕ 2025-10-31 10:09:05 +01:00 committed by GitHub
parent bcc863ab45
commit f0abd7cb7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ challengeType: 19
dashedName: how-do-loops-and-iteration-work-in-javascript
---
# --description--
# --interactive--
Loops in programming are used to repeat a block of code multiple times.
@ -29,12 +29,16 @@ If the condition is true, the code block inside the loop is executed. If the con
The last part of the loop is the increment/decrement statement. This statement is executed after each iteration of the loop. It is typically used to increment or decrement the counter variable.
:::interactive_editor
```js
for (let i = 0; i < 5; i++) {
console.log(i);
}
```
:::
In the first part of the example above, we initialize a counter variable `i` to `0`. It is common convention to use `i` as the counter variable in a `for` loop.
The next part is to check the condition. In this case, the condition is checking if `i` is less than `5`. Since `i` is `0`, the condition is true, and the code block inside the loop is executed.