pxt-calliope/docs/reference/loops/for.md

29 lines
588 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# For
2016-04-02 01:22:47 +02:00
Repeat code a preset number of times.
2016-03-26 00:47:20 +01:00
### @parent blocks/language
Repeat code a fixed number of times.
### Block Editor
![](/static/mb/events-0.png)
The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times:
```
for (let k = 0; k < 4; k++) {
}
```
### Lessons
2016-04-13 17:27:45 +02:00
[looper](/lessons/looper)
2016-03-26 00:47:20 +01:00
### See also
2016-04-18 17:33:09 +02:00
[while](/reference/loops/while), [if](/reference/logic/if)
2016-03-26 00:47:20 +01:00