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