Identify Errors in Algorithms Flashcards

All 6 cards in this deck

What is a syntax error?

An error that occurs when code does not follow the rules of the programming language.

What is a logic error?

An error where the program runs without stopping but does not do what is expected.

Give two examples of syntax errors in code.

Misspelling a statement/keyword and a missing bracket or quotation mark.
Also: using a variable before it is declared, spaces in a variable name.

Give two examples of logic errors in code.

Using the wrong logical/Boolean operator and creating an infinite loop.
Also: brackets in the wrong place in a calculation, or an array element outside scope.

True or false? A program containing a syntax error will still run but give the wrong answer.

False. A program will not run with a syntax error; it is a logic error that runs but gives incorrect results.

What are the steps to identify and correct a logic error in a given algorithm?

e.g. line 03 reads total = num1 - num2 but the two numbers should be added

  1. Compare what each line does with what the program should do: line 03 subtracts
  2. State the line number: Line 03
  3. Give the corrected code, or an unambiguous description of the change: total = num1 + num2