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