Migrate docs from the other repo

This commit is contained in:
Michal Moskal
2016-03-25 16:47:20 -07:00
parent 38d2cf06d2
commit a08eb53f92
895 changed files with 36888 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# For
Repeat code a preset number of times. #docs #for #endfor #language
### @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
[looper](/microbit/lessons/looper)
### See also
[while](/microbit/reference/loops/while), [if](/microbit/blocks/if)

View File

@ -0,0 +1,21 @@
# Repeat
Repeat code a preset number of times. #docs #repeat #language
Repeat code a fixed number of times.
### Block Editor
![](/static/mb/blocks/contents-0.png)
### Touch Develop
Touch Develop has no `repeat` loop. Instead you can used a for loop
```
for (let i = 0; i < 5; i++) {
}
```
The loop above will repeat five (5) times.

View File

@ -0,0 +1,43 @@
# While
Repeat code in a loop while a condition is true. #docs #while #language
### @parent blocks/language
Repeat code while a [Boolean](/microbit/reference/types/boolean) `condition` is true.
### ~hide
```
let condition = false
```
### ~
### Block Editor
![](/static/mb/string-0.png)
The while loop has a *condition* that evaluates to a [Boolean](/microbit/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`.
The condition is tested before any code runs. Which means that if the condition is false, the code inside the loop doesn't execute.
### Example: diagonal line
The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`).
// index is set to 4
![](/static/mb/blocks/var-10.png)
// subtract 1 from `index` each time through loop
### Lessons
[rotation animation](/microbit/lessons/rotation-animation)
### See also
[on button pressed](/microbit/reference/input/on-button-pressed), [for](/microbit/reference/loops/for), [if](/microbit/blocks/if), [forever](/microbit/reference/basic/forever)