Course 4: Intro to For Loops
-
0:05 - 0:10When you use a repeat block to loop your code
how does the computer know when it's repeated -
0:10 - 0:16enough times? The repeat block is actually
hiding a more sophisticated piece of code -
0:16 - 0:22called a for loop which counts from a starting
value up to an ending value by a specific -
0:22 - 0:31increment. For example, a repeat 3 block counts
from 1 to 3 by 1. Every time it counts, it -
0:31 - 0:36runs the code inside the loop. The for loop
knows how many times it has run by using a -
0:36 - 0:40counter variable that is set to the starting
value at the beginning of the loop and has -
0:40 - 0:44the increment added to it each time the loop
is run. As soon as the counter variable is -
0:44 - 0:51greater than the ending value the loop stops
running. The benefit of using a real for loop -
0:51 - 0:55instead of the repeat block is that you can
actually see the counter variable and use -
0:55 - 0:56it in your loop.
奕德 余 edited English subtitles for Course 4: Intro to For Loops |