Robotics Worksheet: Robot If / Else
Robot tip (True → if, false → else): Put the reading into the condition: true → the if part, false → the else part. < means strictly less; an equal reading makes it false. else if: check the conditions from the top; the first true one wins. while: repeat until the condition is false.
NameDateTime takenScore ___ / 40
-
1.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 11 cm. What does the robot do? (a) go forward (b) turn right -
2.🤖 A robot is 109 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
3.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 12 cm. What does the robot do? (a) turn right (b) go forward - 4.🤖 In “if (distance < 20)”, what runs when the distance is exactly 20? (a) the if part (b) both parts (c) neither part (d) the else part
-
5.🤖 if (bumper is pressed) { back up and turn left } else { go forward }
The bumper is not pressed. What does the robot do? (a) back up and turn left (b) go forward -
6.🤖 if (bumper is pressed) { back up and turn right } else { go forward }
The bumper is pressed. What does the robot do? (a) go forward (b) back up and turn right -
7.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 22 cm. What does the robot do? (a) turn right (b) go forward -
8.🤖 A robot is 36 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
9.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 15 cm and the light reading is 35. What does the robot do? (a) stop (b) go forward (c) turn left -
10.🤖 if (bumper is pressed) { back up and turn left } else { go forward }
The bumper is pressed. What does the robot do? (a) go forward (b) back up and turn left - 11.🤖 Obstacle avoiding: what should a robot do when something is close? (a) speed up (b) push it hard (c) close its eyes (d) stop or turn away
-
12.🤖 A robot is 85 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
13.🤖 A robot is 31 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
14.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 7 cm and the light reading is 40. What does the robot do? (a) turn left (b) go forward (c) stop -
15.🤖 if (bumper is pressed) { back up and turn right } else { go forward }
The bumper is not pressed. What does the robot do? (a) back up and turn right (b) go forward -
16.🤖 A robot is 40 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
17.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 37 cm. What does the robot do? (a) turn right (b) go forward -
18.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 21 cm. What does the robot do? (a) go forward (b) turn right -
19.🤖 A robot is 105 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
20.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 13 cm. What does the robot do? (a) turn right (b) go forward -
21.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 26 cm. What does the robot do? (a) turn right (b) go forward -
22.🤖 A robot is 68 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
23.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 29 cm. What does the robot do? (a) go forward (b) turn right -
24.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 25 cm. What does the robot do? (a) go forward (b) turn right -
25.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 25 cm and the light reading is 25. What does the robot do? (a) go forward (b) stop (c) turn left -
26.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 10 cm. What does the robot do? (a) go forward (b) turn right -
27.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 30 cm and the light reading is 80. What does the robot do? (a) go forward (b) turn left (c) stop -
28.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 15 cm. What does the robot do? (a) go forward (b) turn right -
29.🤖 A robot is 48 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
30.🤖 A robot is 77 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
31.🤖 A robot is 102 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
32.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 14 cm and the light reading is 25. What does the robot do? (a) turn left (b) stop (c) go forward -
33.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 13 cm. What does the robot do? (a) go forward (b) turn right -
34.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 6 cm and the light reading is 55. What does the robot do? (a) stop (b) go forward (c) turn left -
35.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 26 cm. What does the robot do? (a) go forward (b) turn right -
36.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 29 cm and the light reading is 25. What does the robot do? (a) turn left (b) go forward (c) stop -
37.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 7 cm. What does the robot do? (a) turn right (b) go forward -
38.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 18 cm. What does the robot do? (a) turn right (b) go forward - 39.🤖 What does an “if” let a robot do? (a) choose using a sensor (b) skip all sensors (c) charge itself (d) go faster always
-
40.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 22 cm and the light reading is 70. What does the robot do? (a) turn left (b) stop (c) go forward
Answer key
- go forward
- 9
- turn right
- the else part
- go forward
- back up and turn right
- go forward
- 2
- go forward
- back up and turn left
- stop or turn away
- 15
- 2
- stop
- go forward
- 2
- go forward
- turn right
- 15
- turn right
- go forward
- 18
- go forward
- go forward
- turn left
- turn right
- go forward
- go forward
- 3
- 6
- 12
- stop
- go forward
- stop
- turn right
- turn left
- turn right
- turn right
- choose using a sensor
- go forward
Free robotics lessons, practice and worksheets at talentjr.in/robotics-for-kids