< Return to Video

Hour of Code - Bill Gates explains If statements

  • 0:01 - 0:03
    People make decisions every day.
  • 0:03 - 0:05
    For example before you go outside
  • 0:05 - 0:07
    you kind of have an IF statement that says,
  • 0:07 - 0:10
    IF it's raining,
    THEN I need to get my jacket.
  • 0:10 - 0:16
    And, computers are amazing once you decide those kinds of statements,
  • 0:16 - 0:21
    that they can reliably execute those things at unbelievable speed.
  • 0:21 - 0:24
    And so, a computer program really
  • 0:25 - 0:28
    is a little bit of math and some
  • 0:28 - 0:31
    IF statements, where the decision gets made.
  • 0:31 - 0:34
    So, in this puzzle the
  • 0:34 - 0:38
    IF block helps the zombie make a decision,
  • 0:38 - 0:40
    it checks something.
  • 0:40 - 0:45
    For example let's use the block that says, "if there's a path to the left,"
  • 0:45 - 0:48
    and put a "turn left" command inside it.
  • 0:48 - 0:52
    So, we're telling the zombie to check its surroundings,
  • 0:52 - 0:54
    see if there's that path on the left,
  • 0:54 - 0:56
    and if so, make that turn.
  • 0:56 - 1:01
    And then we use the "move forward" block inside this "repeat"
  • 1:01 - 1:04
    to get it to keep moving forward as long as
  • 1:04 - 1:06
    it just wants to go straight.
  • 1:06 - 1:12
    Then when there's the turn, the IF block
    will tell it to make this turn to the left.
  • 1:12 - 1:14
    And you can see, if we do that
  • 1:14 - 1:18
    if we're taking the turn to the left and otherwise moving forward,
    we'll achieve our goal.
  • 1:18 - 1:22
    So it's an example of using an IF statement,
  • 1:22 - 1:26
    which is really a fundamental concept in computer programming.
  • 1:26 - 1:32
    One of the first things I learned was how to write a program to play tic-tac-toe.
  • 1:32 - 1:35
    So I had IF statements to say okay,
  • 1:35 - 1:39
    IF the other person is about to win go ahead and block that spot.
  • 1:39 - 1:44
    So have fun learning how to use IF statements. It's a key concept.
Title:
Hour of Code - Bill Gates explains If statements
Video Language:
English
Team:
Code.org
Project:
Hour of Code
Duration:
01:47

English subtitles

Revisions