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