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