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