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