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