Skip to main content

Lesson 3: Using Conditionals

In the previous Lesson, you reached the end of the Disk Maze using the Eye Sensor and while loops. This Lesson introduces the if statement and how to use this statement in the Disk Maze Challenge.

start to end

Learning Outcomes

  • Identify that the if statement runs the blocks inside of it if the Boolean condition is reported to be True.
  • Identify that you can have multiple if statements in a project to be able check for multiple colors, and have multiple behaviors based on those colors.

Observing Patterns and Using Conditional Statements

In Lesson 2, a pattern was identified for the way the VR Robot must drive when a specific color is reported by the Eye Sensor on the Disk Maze Playground.

  • Front Eye Sensor detects ‘GREEN’: True
    • Turn right 90 degrees
      turn right 90 degrees
  • Front Eye Sensor detects ‘BLUE’: True
    • Turn left 90 degrees
      turn left highlights

This logic can be used to simplify a project with the if statement. If statements are conditional statements that instruct the VR Robot to make a decision if a specified condition is True.image of the if statement in the Toolbox and in the workspace

For Your Information

When an if statement is dragged into the Workspace from the Toolbox, a pass statement is automatically populated. The pass statement is a placeholder for a future command to be implemented. The if statement will need to have a command inside of it in order to run, so the pass statement is added. When you add commands to the if statement, they will replace the pass statement. 
if statement in the workspace showing how the pass statement is replaced

Disk Maze Pattern with if statements

If statements in coding follow familiar logic. For example, you have probably used if statements to make decision in your life – "If it is raining, then I use an umbrella." or "If I see a stop sign, then I stop moving." The same pattern we identified in the Disk Maze using while loops, can be reframed to a series of if statements. 

  • If the Front Eye Sensor detects ‘GREEN', then turn right 90 degrees.turn right 90 degrees
  • If the Front Eye Sensor detects 'BLUE', then turn left 90 degrees.turn left highlights

Select the Next button to continue with the rest of this Lesson.