Logic error

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 wrong subroutine, 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'.
#include

int money, money_in_store;

int main(){ do { printf("Enter amount of money (0 to exit): "); scanf("%d", &money); if (money_in_store = 0) // Should be 'if (money = 0)' { printf("%d money on exit ", money_in_store); exit(0); } money_in_store += money; } while(1);

return 0;}

ee also

*Syntax error


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • logic error — loginė klaida statusas T sritis informatika apibrėžtis Programos tekste esanti ↑klaida, neaptinkama programos ↑kompiliavimo arba ↑vykdymo metu, tačiau sukelianti nelauktus programos vykdymo rezultatus. atitikmenys: angl. logic error; logical… …   Enciklopedinis kompiuterijos žodynas

  • Error — The word error has different meanings and usages relative to how it is conceptually applied. The concrete meaning of the Latin word error means wandering or straying . To the contrary of an illusion, an error or a mistake can sometimes be… …   Wikipedia

  • Logic — • A historical survey from Indian and Pre Aristotelian philosophy to the Logic of John Stuart Mill Catholic Encyclopedia. Kevin Knight. 2006. Logic     Logic      …   Catholic encyclopedia

  • Logic and the philosophy of mathematics in the nineteenth century — John Stillwell INTRODUCTION In its history of over two thousand years, mathematics has seldom been disturbed by philosophical disputes. Ever since Plato, who is said to have put the slogan ‘Let no one who is not a geometer enter here’ over the… …   History of philosophy

  • Logic bomb — A logic bomb is a piece of code intentionally inserted into a software system that will set off a malicious function when specified conditions are met. For example, a programmer may hide a piece of code that starts deleting files (such as a… …   Wikipedia

  • Error code — In computer programming, error codes are enumerated messages that correspond to faults in a specific software application. They are typically used to identify faulty hardware, software, or incorrect user input in programming languages that lack… …   Wikipedia

  • Syntax error — In computer science a syntax error ( IPA: /ˈsɪntæks ɛrə(ɹ)/ ) refers to an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language.If a syntax error is encountered during… …   Wikipedia

  • logical error — loginė klaida statusas T sritis informatika apibrėžtis Programos tekste esanti ↑klaida, neaptinkama programos ↑kompiliavimo arba ↑vykdymo metu, tačiau sukelianti nelauktus programos vykdymo rezultatus. atitikmenys: angl. logic error; logical… …   Enciklopedinis kompiuterijos žodynas

  • Soft error — In electronics and computing, an error is a signal or datum which is wrong. Errors may be caused by a defect, usually understood either to be a mistake in design or construction, or a broken component. A soft error is also a signal or datum which …   Wikipedia

  • History of logic — Philosophy ( …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”