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