The numbers in the for
block work as you probably think they do: the
inner script is run enough times to count from the left number (1
)
to the right
number (10
). As with the repeat
block, you can change the numbers
it comes with by default to change the way the block repeats.
What's new to you here, though, is the orange oval with "i
" in it.
By using this i
, your inner blocks can know which time through the loop
they are currently on. Here's how:
The block is a variable
that acts like a counter. You use it any place you would use a number,
and it will report the value that it currently holds.
Think of the variable like a box with a name—this one has the name i
.
This box is made for you by the block, and
holds a different number each time through the loop. The first time it will hold
1
, or whatever is the left number in the for
block.
You use it by dragging
from the source within the
for
block down to the slot in
which you will use it.
For instance:
is the equivalent of