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