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