Logic Error

Why Trust Techopedia

What Does Logic Error?

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.

Advertisements

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 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.

Advertisements

Related Terms

Margaret Rouse
Technology Specialist
Margaret Rouse
Technology Specialist

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.