YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Hour of Code - Mark Zuckerburg teaches Repeat Loops

Get Embed Code
20 Languages

Showing Revision 1 created 11/21/2013 by Amara Bot.

  1. One thing that computers are really good
    at is repeating commands.
  2. As a person, you'd get really bored if you
    had to do the same thing lots of times in a row.
  3. But a computer can do the same thing
    millions or even billions of times,
  4. and not get bored and be able to carry
    that out really well.
  5. So for example if I wanted to wish
  6. everyone on Facebook a happy birthday by
    sending them an email,
  7. it might take me more than a century to
    actually write out all of those emails to everyone.
  8. But with just a few lines of code, I can have
    a system
  9. send an email to everyone on Facebook
    wishing them a happy birthday.
  10. So that's what loops are, and why they're
    valuable,
  11. and something that computers can do very well.
  12. In this example your goal is going to be
    to move the bird
  13. to get the pig. Now we're gonna be able to use the "repeat" block
  14. in order to be able to do this very
    easily. You can either do this by
  15. giving the computer a "move forward"
    command
  16. five times in order to advance the bird
    one step each time to the pig.
  17. Or you can just tell the computer to
    "move forward" once,
  18. and then tell it to "repeat" that 5
    times, and it will do the same thing.
  19. So in order to do this you drag your
    "move forward" command,
  20. and then you put it inside the
    "repeat" block.
  21. And you can click on it and tell it how
    many times you want to repeat the block
  22. to tell it how many steps you want it to
    take forward. Now one more thing is
  23. you can put as many commands as you
    want inside the "repeat" block.
  24. So in this example you're telling it to
    move forward and turn left,
  25. which it will do five times. Alright good
    job and have fun :-)