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.🤖 What does an “if” let a robot do? (a) charge itself (b) go faster always (c) skip all sensors (d) choose using a sensor
- 2.🤖 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
-
3.🤖 A robot is 81 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
4.🤖 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 -
5.🤖 A robot is 51 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
6.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 22 cm and the light reading is 80. What does the robot do? (a) stop (b) turn left (c) go forward -
7.🤖 A robot is 63 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
8.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 13 cm. What does the robot do? (a) turn right (b) go forward -
9.🤖 A robot is 89 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
10.🤖 A robot is 49 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
11.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 13 cm and the light reading is 65. What does the robot do? (a) go forward (b) stop (c) turn left -
12.🤖 A robot is 52 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
13.🤖 A robot is 65 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
14.🤖 A robot is 31 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
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.🤖 A robot is 41 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
17.🤖 A robot is 100 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
18.🤖 A robot is 54 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 < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 17 cm and the light reading is 40. What does the robot do? (a) stop (b) turn left (c) go forward -
20.🤖 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 -
21.🤖 A robot is 109 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
22.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 15 cm and the light reading is 15. What does the robot do? (a) go forward (b) stop (c) turn left -
23.🤖 if (distance < 20) { turn right } else { go forward }
The distance sensor reads 18 cm. What does the robot do? (a) go forward (b) turn right -
24.🤖 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 -
25.🤖 A robot is 50 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
26.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 28 cm and the light reading is 55. What does the robot do? (a) turn left (b) go forward (c) stop -
27.🤖 A robot is 69 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
28.🤖 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)? -
29.🤖 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 -
30.🤖 A robot is 93 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward? -
31.🤖 if (distance < 25) { turn right } else { go forward }
The distance sensor reads 18 cm. What does the robot do? (a) go forward (b) turn right -
32.🤖 A robot is 43 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
33.🤖 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 -
34.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 19 cm and the light reading is 55. What does the robot do? (a) turn left (b) stop (c) go forward -
35.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 31 cm and the light reading is 15. What does the robot do? (a) turn left (b) go forward (c) stop -
36.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 32 cm and the light reading is 35. What does the robot do? (a) stop (b) turn left (c) go forward -
37.🤖 A robot is 61 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How far from the wall does it stop (in cm)? -
38.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
The distance is 26 cm and the light reading is 50. What does the robot do? (a) stop (b) go forward (c) turn left -
39.🤖 A robot is 50 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 38 cm from a wall. It runs:
while (distance > 20) { forward 10 cm }
stop
How many times does it move forward?
Answer key
- choose using a sensor
- the else part
- 7
- turn right
- 4
- go forward
- 5
- turn right
- 19
- 3
- stop
- 4
- 5
- 11
- back up and turn left
- 11
- 8
- 14
- go forward
- back up and turn right
- 9
- turn left
- turn right
- go forward
- 3
- go forward
- 19
- 15
- go forward
- 8
- turn right
- 13
- go forward
- go forward
- turn left
- go forward
- 11
- go forward
- 20
- 2
Free robotics lessons, practice and worksheets at talentjr.in/robotics-for-kids