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