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 (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 -
2.🤖 A robot is 70 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
3.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 20 cm and the light reading is 85. What does the robot do? (a) turn left (b) go forward (c) stop -
4.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 7 cm and the light reading is 75. What does the robot do? (a) go forward (b) stop (c) turn left - 5.🤖 Obstacle avoiding: what should a robot do when something is close? (a) speed up (b) push it hard (c) stop or turn away (d) close its eyes
-
6.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 27 cm. What does the robot do? (a) turn right (b) go forward -
7.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 21 cm. What does the robot do? (a) turn right (b) go forward -
8.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 35 cm. What does the robot do? (a) turn right (b) go forward -
9.🤖 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 -
10.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 33 cm and the light reading is 25. What does the robot do? (a) turn left (b) go forward (c) stop -
11.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 23 cm. What does the robot do? (a) go forward (b) turn right -
12.🤖 A robot is 41 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? - 13.🤖 In “if (distance < 20)”, what runs when the distance is exactly 20? (a) neither part (b) the if part (c) both parts (d) the else part
-
14.🤖 A robot is 39 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
15.🤖 A robot is 70 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
16.🤖 A robot is 35 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
17.🤖 A robot is 40 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
18.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 19 cm and the light reading is 15. What does the robot do? (a) turn left (b) stop (c) go forward -
19.🤖 A robot is 38 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 < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 13 cm and the light reading is 25. What does the robot do? (a) go forward (b) turn left (c) stop -
21.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 40 cm and the light reading is 15. What does the robot do? (a) stop (b) go forward (c) turn left -
22.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 24 cm. What does the robot do? (a) turn right (b) go forward -
23.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 14 cm and the light reading is 90. What does the robot do? (a) go forward (b) stop (c) turn left -
24.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 21 cm. What does the robot do? (a) turn right (b) go forward -
25.🤖 A robot is 46 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
26.🤖 A robot is 93 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
27.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 22 cm. What does the robot do? (a) go forward (b) turn right -
28.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 39 cm and the light reading is 45. What does the robot do? (a) go forward (b) stop (c) turn left -
29.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 19 cm and the light reading is 90. What does the robot do? (a) stop (b) go forward (c) turn left -
30.🤖 A robot is 54 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? - 31.🤖 What does an “if” let a robot do? (a) go faster always (b) skip all sensors (c) charge itself (d) choose using a sensor
-
32.🤖 A robot is 43 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
33.🤖 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 -
34.🤖 if (bumper is pressed) { back up and turn left } else { go forward }
The bumper is not pressed. What does the robot do? (a) go forward (b) back up and turn left -
35.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 36 cm and the light reading is 60. What does the robot do? (a) go forward (b) turn left (c) stop -
36.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 41 cm. What does the robot do? (a) go forward (b) turn right -
37.🤖 A robot is 66 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
38.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 2 cm. What does the robot do? (a) turn right (b) go forward -
39.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 24 cm. What does the robot do? (a) go forward (b) turn right -
40.🤖 A robot is 80 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward?
Answer key
- back up and turn left
- 20
- go forward
- stop
- stop or turn away
- go forward
- turn right
- go forward
- back up and turn right
- turn left
- turn right
- 3
- the else part
- 2
- 5
- 2
- 20
- turn left
- 18
- stop
- turn left
- go forward
- stop
- go forward
- 3
- 8
- go forward
- go forward
- go forward
- 4
- choose using a sensor
- 3
- go forward
- go forward
- go forward
- go forward
- 5
- turn right
- go forward
- 6
Free robotics lessons, practice and worksheets at talentjr.in/robotics-for-kids