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