Comet lays four pages of Beacon pseudocode on the bench. "Each one has a bug," she admits. "I wrote them all."
Wren grins. "Then you have given us four clues."
Nova sweeps a beam of light over the pages, and a small glowing marker appears beside each one.
"Let's debug together," Nova says. "But first, name each kind of bug. Different kinds hide in different places."
Comet picks up the first page. "This one will not even run. I spelled a word wrong."
"That is one kind," Wren says. "Let's find the other three."
A logic error is a mistake in the algorithm or program that makes it behave incorrectly or unexpectedly.
A syntax error is a mistake where the rules of the programming language are not followed.
A run-time error is a mistake that occurs while the program is running.
An overflow error happens when a computer tries to handle a number outside its defined range of values.
PAGE 1
REPEAT 24 TIMS
{
checkPlant(waterLevel)
}
PAGE 2 (requirement: alert when the level is below 30)
IF (waterLevel ≤ 30)
{
DISPLAY("The tomatoes need water")
}
PAGE 3
readings ← [40, 55, 62]
DISPLAY(readings[4])
PAGE 4 (readingCount can hold whole numbers from 0 to 255)
readingCount ← 255
readingCount ← readingCount + 1 On the AP reference sheet, list indexes run from 1 to the length of the list.
If an index is less than 1 or greater than the length, an error message is produced and the program stops running.
Here is a loop that displays every reading. Trace it, and watch the index.
readings ← [40, 55, 62]
index ← 1
REPEAT UNTIL (index > 4)
{
DISPLAY(readings[index])
index ← index + 1
} | Statement | True or false? |
|---|---|
| A program with a logic error can run without any error message. | ? |
| A syntax error breaks the rules of the programming language. | ? |
| Asking for index 0 of a list is fine on the AP reference sheet. | ? |
| Comet should be embarrassed about her bugs. | ? |
Nice bug hunting. Tomorrow's Beacon Lab tracks down a quiet logic error.