What Does Logic Error Mean?
A logic error is an error in a program’s source code that
gives way to unanticipated and erroneous behavior. A logic error is classified as a type of runtime
error that can result in a program producing an incorrect output. It can also cause
the program to crash when running.
Logic errors are
not always easy to recognize immediately. This is due to the fact that such
errors, unlike that of syntax errors, are valid when considered in the language,
but do not produce the intended behavior. These can occur in both interpreted
and compiled languages.
A logic error is also known as a logical error.
Techopedia Explains Logic Error
Logic errors cause a program to work
incorrectly. For example, in PHP, when "if ($i=1) {…}" is incorrectly entered instead of "if ($i==1) {….}," the former means
"becomes" while the latter means "is equal to." The incorrect if statement would always return TRUE as assigning 1 to the variable $i. In the correct version, though, the statement only returns TRUE when
the value of variable $i is equal to 1. The syntax in the incorrect
case is perfectly correct as per the language. So, the code would compile
successfully without producing any syntax errors. However, during runtime of
the code, the resultant output may be wrong, thus showing that a certain logic
error has occurred. Logic errors tend to be hidden in the source code and can
typically be harder to determine and debug, unlike syntax errors that are
recognized at compile time.