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.🤖 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
-
2.🤖 A robot is 68 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
3.🤖 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)? -
4.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 12 cm. What does the robot do? (a) turn right (b) go forward -
5.🤖 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 -
6.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 29 cm and the light reading is 60. What does the robot do? (a) stop (b) turn left (c) go forward -
7.🤖 A robot is 63 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
8.🤖 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 -
9.🤖 A robot is 72 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
10.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 31 cm. What does the robot do? (a) go forward (b) turn right -
11.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 37 cm. What does the robot do? (a) turn right (b) go forward -
12.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 12 cm and the light reading is 30. What does the robot do? (a) go forward (b) turn left (c) stop -
13.🤖 if (bumper is pressed) { back up and turn right } else { go forward }
The bumper is pressed. What does the robot do? (a) back up and turn right (b) go forward -
14.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 23 cm and the light reading is 15. What does the robot do? (a) go forward (b) turn left (c) stop -
15.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 26 cm and the light reading is 80. What does the robot do? (a) stop (b) turn left (c) go forward -
16.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 20 cm and the light reading is 25. What does the robot do? (a) stop (b) turn left (c) go forward - 17.🤖 In “if (distance < 20)”, what runs when the distance is exactly 20? (a) both parts (b) the if part (c) the else part (d) neither part
-
18.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 7 cm and the light reading is 80. What does the robot do? (a) go forward (b) turn left (c) stop - 19.🤖 What does an “if” let a robot do? (a) charge itself (b) skip all sensors (c) go faster always (d) choose using a sensor
-
20.🤖 A robot is 58 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
21.🤖 A robot is 83 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
22.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 28 cm and the light reading is 15. What does the robot do? (a) stop (b) turn left (c) go forward -
23.🤖 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)? -
24.🤖 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 -
25.🤖 A robot is 64 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
26.🤖 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 -
27.🤖 A robot is 36 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
28.🤖 A robot is 39 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
29.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 17 cm. What does the robot do? (a) turn right (b) go forward -
30.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 38 cm. What does the robot do? (a) turn right (b) go forward -
31.🤖 A robot is 66 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
32.🤖 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)? -
33.🤖 A robot is 73 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 28 cm and the light reading is 10. What does the robot do? (a) go forward (b) stop (c) turn left -
35.🤖 A robot is 76 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
36.🤖 A robot is 109 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 5 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 11 cm and the light reading is 35. 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 17 cm. What does the robot do? (a) turn right (b) go forward -
40.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 32 cm. What does the robot do? (a) go forward (b) turn right
Answer key
- stop or turn away
- 5
- 12
- go forward
- back up and turn left
- go forward
- 13
- go forward
- 12
- go forward
- go forward
- stop
- back up and turn right
- turn left
- go forward
- turn left
- the else part
- stop
- choose using a sensor
- 4
- 7
- turn left
- 11
- go forward
- 14
- go forward
- 16
- 2
- turn right
- go forward
- 16
- 16
- 13
- turn left
- 16
- 9
- turn right
- stop
- go forward
- go forward
Free robotics lessons, practice and worksheets at talentjr.in/robotics-for-kids