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