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