Rocket wanted the steps box to reach 5.
But his loop stopped at 4.
Rocket laughs. He counted one lap short!
Coders call this an off by one bug.
Even grown-up coders make this bug.
Raven says it is a great bug to hunt.
Rocket wants steps to reach 5.
But his loop runs only 4 laps.
Steps stops at 4. One short!
set steps to 0 repeat 4 times: change steps by 1 move right stop say steps
Off by one means one too few.
Or it means one too many.
Count the laps to find it.
| first line | loop line | ends on 5? |
|---|---|---|
| set steps to 0 | repeat 4 times: | ? |
| set steps to 0 | repeat 5 times: | ? |
| set steps to 1 | repeat 4 times: | ? |
| set steps to 1 | repeat 5 times: | ? |
Fix the flight a new way.
Steps starts at 1 this time.
Nova must say 5.
Look at the height column.
It stays at 3, then drops to 1.
The drop happens on lap 5.
Steps holds 5 right then!
| clue | true? |
|---|---|
| height drops on lap 5 | ? |
| steps holds 5 at the drop | ? |
| height drops on lap 2 | ? |
| height goes up at the drop | ? |
Off by one: one lap too few or many.
Count laps and check the start.
The drop came when steps held 5.
Great detective work, Crew!