TyroCity

Discuss User for Discuss

Posted on

logical errors are difficult to debug compared to syntax error. Justify?

A logic error (or logical error) is a mistake in a program’s source code that results in incorrect or unexpected behavior. It is a type of runtime error that may simply produce the wrong output or may cause a program to crash while running.

Many different types of programming mistakes can cause logic errors. For example, assigning a value to the wrong variable may cause a series of unexpected program errors. Multiplying two numbers instead of adding them together may also produce unwanted results. Even small typos that do not produce syntax errors may cause logic errors. In the PHP code example below, the if statement may cause a logic error since the single equal sign (=) should be a double equal sign (==).

Incorrect: if ($i=1) { … }

Correct: if ($i==1) { … }
Enter fullscreen mode Exit fullscreen mode

Missing a simple dot, comma, symbol, a miss spelling can every easily result to logic error. Given that in a programming language where there’s hundreds and thousands of lines of code, it’s really difficult to pin point where exactly the error might be happening to resolve.

However, for the syntax error as it’s an error in the source code of a program. Since computer programs must follow strict syntax to compile correctly, any aspects of the code that do not conform to the syntax of the programming language will produce a syntax error. As, there’s a fixed set of lines that you need to use - you can very easily find it and fix it as required.

This post was part of TyroCity discussion forum
Question asked by laZor_Plays
Answered by aadarsh_gautam

Discussion (0)