Return to Video

Hour of Code - Mark Zuckerburg teaches Repeat Loops

  • 0:00 - 0:04
    One thing that computers are really good
    at is repeating commands.
  • 0:04 - 0:08
    As a person, you'd get really bored if you
    had to do the same thing lots of times in a row.
  • 0:08 - 0:09
  • 0:09 - 0:13
    But a computer can do the same thing
    millions or even billions of times,
  • 0:13 - 0:15
    and not get bored and be able to carry
    that out really well.
  • 0:16 - 0:17
    So for example if I wanted to wish
  • 0:17 - 0:21
    everyone on Facebook a happy birthday by
    sending them an email,
  • 0:21 - 0:25
    it might take me more than a century to
    actually write out all of those emails to everyone.
  • 0:25 - 0:25
  • 0:25 - 0:29
    But with just a few lines of code, I can have
    a system
  • 0:29 - 0:32
    send an email to everyone on Facebook
    wishing them a happy birthday.
  • 0:32 - 0:34
    So that's what loops are, and why they're
    valuable,
  • 0:34 - 0:37
    and something that computers can do very well.
  • 0:37 - 0:41
    In this example your goal is going to be
    to move the bird
  • 0:41 - 0:45
    to get the pig. Now we're gonna be able to use the "repeat" block
  • 0:45 - 0:49
    in order to be able to do this very
    easily. You can either do this by
  • 0:49 - 0:52
    giving the computer a "move forward"
    command
  • 0:52 - 0:57
    five times in order to advance the bird
    one step each time to the pig.
  • 0:57 - 1:01
    Or you can just tell the computer to
    "move forward" once,
  • 1:01 - 1:04
    and then tell it to "repeat" that 5
    times, and it will do the same thing.
  • 1:04 - 1:08
    So in order to do this you drag your
    "move forward" command,
  • 1:08 - 1:12
    and then you put it inside the
    "repeat" block.
  • 1:12 - 1:16
    And you can click on it and tell it how
    many times you want to repeat the block
  • 1:16 - 1:20
    to tell it how many steps you want it to
    take forward. Now one more thing is
  • 1:20 - 1:24
    you can put as many commands as you
    want inside the "repeat" block.
  • 1:24 - 1:27
    So in this example you're telling it to
    move forward and turn left,
  • 1:27 - 1:31
    which it will do five times. Alright good
    job and have fun :-)
  • 1:31 - 1:31
Title:
Hour of Code - Mark Zuckerburg teaches Repeat Loops
Video Language:
English
Team:
Code.org
Project:
Hour of Code
Duration:
01:35

English subtitles

Revisions