İçeriğe atla
2027 - 2028 Sınavları için kontenjanlarımız açıkBaşvuru
ITMagicITMagicAcademy
Tüm konular
AP Computer Science PrinciplesÜnite 1 · Creative Development

Identifying and Correcting Errors

Recognize syntax, runtime, logic and overflow errors, and use testing, hand tracing and debugging strategies to find and fix them.

Types of errors

ErrorWhat happensExample
syntax errorthe rules of the language are broken; the program does not runa missing bracket
runtime errorthe program fails while runningdividing by zero, an index outside a list
logic errorthe program runs but gives the wrong resultusing > instead of ≥
overflow errora number is too large for the space reserved for itadding past the largest value

Logic errors are the hardest to find because nothing crashes.

Finding errors

  • Test cases: choose inputs and the expected outputs, including boundary and unusual values (0, negative numbers, empty lists, the largest allowed value).
  • Hand tracing: follow the code line by line, recording variable values in a table.
  • Visualizations and debuggers: step through code.
  • Adding output statements to display intermediate values.

Example of a logic error

The procedure should count the scores of at least 50:

count ← 0
FOR EACH s IN scores
{
  IF (s > 50)
  {
    count ← count + 1
  }
}

A score of exactly 50 is not counted. The condition should be s ≥ 50. A test case containing the boundary value 50 reveals the error.

Quick summary

  • Syntax errors stop the program; logic errors give wrong answers silently.
  • Test boundaries and unusual inputs.
  • Hand-trace with a table of values.

Konu quizi

5 soru. Geçmek için en az %80 doğru gerekiyor; geçince sonraki konu açılır.

Quizi çözüp ilerlemeni kaydetmek için giriş yap. Hesap açmak ücretsiz.

Giriş yap ve quizi çöz