- Logic error
In
computer programming , a logic error (sometimes called a semantic error) is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally (or crash). A logic error produces unintended or undesired output or other behavior, although it may not immediately be recognized as such.Logic errors occur in both compiled and interpreted languages. Unlike a program with a
syntax error , a program with a logic error is a valid program in the language, though it does not behave as intended.Common causes
The mistake could be the logical error in a statement (for example, a wrong or incorrect formula), an error in an
algorithm , or even the wrong algorithm selected.Debugging logic errors
One of the ways to find these type of errors is to output the program's
variables to a file or on the screen in order to define the error's location in code. Although this will not work in all cases, for example when calling the wrongsubroutine , it is the easiest way to find the problem if the program uses the incorrect results of a bad mathematical calculation.Examples
This example in C contains a logic error. After '
', 'scanf money_in_store
' is checked instead of 'money
'.ee also
*
Syntax error
Wikimedia Foundation. 2010.