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