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