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