pxt-calliope/docs/lessons/looper/activity.md
2016-03-25 16:47:20 -07:00

1014 B

looper blocks activity

Display a series of numbers with a for loop.

~avatar avatar

@video td/videos/looper-0

~

Welcome! This activity will teach how to display a series of numbers for a for loop. Let's get started!

Let's create a for loop where 0 is the loop's starting value, i is the index variable, and 5 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 = 5.

for (let i = 0; i < 6; i++) {
    
}

We will show the number of times the loop has been executed. It will go from zero to five times.

for (let i = 0; i < 6; i++) {
    basic.showNumber(i)
}

The for loop while cycle through to six immediately unless we pause for a little bit in between each loop.

for (let i = 0; i < 6; i++) {
    basic.showNumber(i)
    basic.pause(2000)
}

~avatar avatar

Excellent, you're ready to continue with the challenges!

~