*** Welcome to piglix ***

Statement (computer science)


In computer programming, a statement is the smallest standalone element of an imperative programming language that expresses some action to be carried out. It is an instruction written in a high-level language that commands the computer to perform a specified action. A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g., expressions).

Many languages (e.g. C) make a distinction between statements and definitions, with a statement only containing executable code and a definition instantiating an identifier, while an expression evaluates to a value only. A distinction can also be made between simple and compound statements; the latter may contain statements as components.

The following are the major generic kinds of statements with examples in typical imperative languages:

The appearance of statements shapes the look of programs. Programming languages are characterized by the type of statements they use (e.g. the curly brace language family). Many statements are introduced by identifiers like if, while or repeat. Often statement keywords are reserved such that they cannot be used as names of variables or functions. Imperative languages typically use special syntax for each statement, which looks quite different from function calls. Common methods to describe the syntax of statements are Backus–Naur form and syntax diagrams.

Semantically many statements differ from subroutine calls by their handling of parameters. Usually an actual subroutine parameter is evaluated once before the subroutine is called. This contrasts to many statement parameters that can be evaluated several times (e.g. the condition of a while loop) or not at all (e.g. the loop body of a while loop). Technically such statement parameters are call-by-name parameters. Call-by-name parameters are evaluated when needed (see also lazy evaluation). When call-by-name parameters are available a statement like behaviour can be implemented with subroutines (see Lisp). For languages without call-by-name parameters the semantic description of a loop or conditional is usually beyond the capabilities of the language. Therefore standard documents often refer to semantic descriptions in natural language.


...
Wikipedia

...