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