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