a1tD0000006jsGdIAI

Course: Introduction to Programming with NAO
6. Conditional Statements

  • 6-9 grade
  • Beginner

Lesson Description:

Lesson Description:
In this lesson, the students will make the NAO robot tell a different story each time by using the Random Int box and If box in Choregraphe.
Introducing new concepts in computer science: if statement and switch case statement

Objectives

  • Identify and define a conditional statement.
  • Get familiar with IF and SWITCH conditional statement.
  • Predict the outcome of a program, given a set of input.
  • Embed the conditional statements in a story. 
  • Create new branches of the story

image description

Lesson Modules


Teaching Tips:

You can download the code for this lesson here.

In this lesson, the students will learn the concept of conditional statements. Such as IF statement and Switch statement. The code you can run to the class has NAO tell 4 different statements.

Statement 1 and 3 are non conditional; statement 2 and 4 are conditional. 

The observe module is here to start the discussion and make the students think about conditional statements. They need to listen to NAO and chose which statements are s conditional and which are not.  

You can bring some real-life examples and have a discussion about real-life examples of If statements.

Question number in the Observe module invites the students to bring their own example.


Listen to NAO and try to figure out the difference between the statements. 

Which statements are conditional? Which statements are not conditional.

Which statements are conditional
  • Statement 1
  • Statement 2
  • Statement 3
  • Statement 4
  • None

Give an example of a conditional statement.



Teaching Tips:

In this module, the students start to explore the boxed If and Switch case in Choregraphe. 

They need to understand the logic of these conditional statements and how to use them in Choregraphe. Next module they will create a story with different potential endings based on conditional statements.

In the example taken for the switch case, they need to use the Random int box ( lesson 5). It is recommended to set the parameters of that box such as to have only numbers 1,2 3 as potential numbers. You do that by cliking on the wrench of the box and set the minimum value at 1 and the final value at 3.

Open your Choregraphe software and explore the If box.

Read below the description to help you make proper use of the box. 

IF Condition


Press the wrench in the bottom left corner of the box.


{{question 1:

Let's say you want to have more than one condition.


Switch Case Condition

In order to have more than two options - Switch Statement.
Switch Statement is a multi IF statements grouped together having the same criteria checked with different values.

Find a Switch Case box under the Flow Control folder and drag it onto the workspace.

Change the options in the middle to 1, 2 and 3.

Drag 3 Animated Say Boxes onto the workspace.
Connect each one of the boxes to a different option port of the Switch Case box.
Each box represents a different ending to the story.


Describe using "if statements" how the switch case box work.


Teaching Tips:

In this module, the students are implementing what they learn about conditional statements to create a story with multiple different outcomes.

First using If. 

Then using Switch case.

They can run the program on the virtual robot and in turn, connect to the real robot to play their story. 


Now that you understand how If and Switch-Case work, create a story with different endings.  

First create two different endings that NAO chose from, using the IF box.

Then chose three different outcomes and use a Switch-Case to chose between the three possibilities.


Describe in your own word the if condition of your story before implementing it.

Describe the 3 options to chose form using the switch case.





Teaching Tips:



AFTER CLASS

Store Student Files
Put the student files on a thumb drive or store them in some way so that the students can continue working on their project in the next lesson. 

Pack Up Hardware
Pack the robots and computers according to the packing instructions.

What is an IF Statement?

In which cases we would prefer to use If statement rather than using a switch case statement?
  • When we want to have ore than 2 branches to the program
  • When we have a criteria with NOT equal to operator
  • When we have a criteria with > (bigger than) operator
  • We will always prefer to use IF statement over switch case statement