pxt-calliope/docs/lessons/looper/quiz-answers.md

41 lines
1.4 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# looper quiz answers
2016-04-02 01:22:47 +02:00
Learn how to create a series of numbers with a for loop.
2016-03-26 00:47:20 +01:00
2016-04-13 17:27:45 +02:00
This is the answer key for the [looper quiz](/lessons/looper/quiz).
2016-03-26 00:47:20 +01:00
## 1. What is a for loop?
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
## 2. Consider the following code
2016-03-30 22:41:01 +02:00
```blocks
2016-03-26 00:47:20 +01:00
for (let i = 0; i < 4; i++) {
basic.showNumber(i, 150)
}
```
If the rectangle below represents the @boardname@, shade the areas that will be displayed. Explain why that particular area is shaded.
2016-03-26 00:47:20 +01:00
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `4` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 4`.
![](/static/mb/lessons/looper-0.png)
## 3. Consider the following code
2016-03-30 22:41:01 +02:00
```blocks
2016-03-26 00:47:20 +01:00
for (let i1 = 0; i1 < 6; i1++) {
basic.showNumber(i1, 150)
}
```
If the rectangle below represents the @boardname@, shade the areas that will be displayed. Explain why that particular area is shaded.
2016-03-26 00:47:20 +01:00
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `6` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 6`.
![](/static/mb/lessons/looper-0.png)
![](/static/mb/lessons/looper-1.png)