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