mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-28 21:00:56 +08:00
feat(curriculum): Add interactive examples to How Do Loops and Iteration Work in JavaScript (#63344)
This commit is contained in:
parent
bcc863ab45
commit
f0abd7cb7b
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user