2016-03-26 00:47:20 +01:00
|
|
|
# digi yoyo activity
|
|
|
|
|
|
|
|
Create a counter with a while loop.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~avatar avatar
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
Welcome! This tutorial will teach how to create a counter with a while loop. Let's get started!
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2018-11-10 00:36:46 +01:00
|
|
|
Create a variable that acts as a counter and set it to `0`.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0
|
|
|
|
```
|
|
|
|
|
2018-11-10 00:36:46 +01:00
|
|
|
Add a while loop that will loop over and over until the variable ``||variables:count||`` equals `10`.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0
|
|
|
|
while (count < 10) {
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-11-10 00:36:46 +01:00
|
|
|
Let's add a pause. Then show the value of ``||variables:count||``.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
2016-04-13 17:51:40 +02:00
|
|
|
let count = 0;
|
2016-03-26 00:47:20 +01:00
|
|
|
while (count < 10) {
|
|
|
|
basic.pause(100);
|
|
|
|
basic.showNumber(count)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-11-10 00:36:46 +01:00
|
|
|
Increase the value of ``||variables:count||`` by one.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0
|
|
|
|
while (count < 10) {
|
|
|
|
basic.pause(100)
|
|
|
|
basic.showNumber(count)
|
2016-04-01 00:51:42 +02:00
|
|
|
count = count + (count - 1)
|
2016-03-26 00:47:20 +01:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~avatar avatar
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
Excellent, you're ready to continue with the [challenges](/lessons/digi-yoyo/challenges)!
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|