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