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