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