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