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 40 cm and the light reading is 70. What does the robot do? (a) turn left (b) stop (c) go forward -
2.🤖 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 -
3.🤖 A robot is 103 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
4.🤖 A robot is 38 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
5.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 42 cm. What does the robot do? (a) turn right (b) go forward -
6.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 31 cm. What does the robot do? (a) go forward (b) turn right -
7.🤖 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 -
8.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 11 cm and the light reading is 25. What does the robot do? (a) go forward (b) turn left (c) stop - 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.🤖 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
-
11.🤖 if (distance < 15) { turn right } else { go forward }
The distance sensor reads 18 cm. What does the robot do? (a) go forward (b) turn right -
12.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 31 cm. What does the robot do? (a) go forward (b) turn right -
13.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 22 cm. What does the robot do? (a) go forward (b) turn right -
14.🤖 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 -
15.🤖 A robot is 101 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
16.🤖 if (distance < 10) { turn right } else { go forward }
The distance sensor reads 21 cm. What does the robot do? (a) turn right (b) go forward -
17.🤖 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) turn left (b) go forward (c) stop -
18.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 23 cm and the light reading is 25. What does the robot do? (a) go forward (b) stop (c) turn left -
19.🤖 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 -
20.🤖 A robot is 77 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 19 cm and the light reading is 15. What does the robot do? (a) go forward (b) stop (c) turn left -
22.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 20 cm and the light reading is 20. What does the robot do? (a) stop (b) turn left (c) go forward -
23.🤖 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 -
24.🤖 A robot is 48 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
25.🤖 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 -
26.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 9 cm and the light reading is 35. What does the robot do? (a) go forward (b) turn left (c) stop -
27.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 6 cm and the light reading is 55. What does the robot do? (a) stop (b) turn left (c) go forward -
28.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 27 cm and the light reading is 65. What does the robot do? (a) go forward (b) stop (c) turn left -
29.🤖 A robot is 77 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
30.🤖 if (distance < 30) { turn right } else { go forward }
The distance sensor reads 36 cm. What does the robot do? (a) go forward (b) turn right -
31.🤖 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 -
32.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 13 cm and the light reading is 70. What does the robot do? (a) stop (b) go forward (c) turn left -
33.🤖 A robot is 40 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
34.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 27 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 27 cm and the light reading is 10. What does the robot do? (a) go forward (b) turn left (c) stop -
36.🤖 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 -
37.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 12 cm and the light reading is 50. What does the robot do? (a) stop (b) go forward (c) turn left -
38.🤖 A robot is 91 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
39.🤖 A robot is 103 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
40.🤖 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
Answer key
- go forward
- back up and turn left
- 9
- 2
- go forward
- go forward
- go forward
- stop
- stop or turn away
- the else part
- go forward
- go forward
- go forward
- go forward
- 11
- go forward
- stop
- turn left
- turn right
- 17
- turn left
- turn left
- turn right
- 3
- go forward
- stop
- stop
- go forward
- 6
- go forward
- turn right
- stop
- 2
- go forward
- turn left
- back up and turn right
- stop
- 11
- 13
- turn right
Free robotics lessons, practice and worksheets at talentjr.in/robotics-for-kids