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