Statement (programming)

Statement (programming)

In computer programming a statement can be thought of as the smallest standalone element of an imperative programming language. A program is formed by a sequence of one or more statements. A statement will have internal components (eg, expressions).

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

Kinds of statements

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

Simple statements

* assignment: A := A + 1
* call: CLEARSCREEN()
* return: return 5;
* goto: goto 1
* assertion: assert(ptr != NULL);

Compound statements

* statement block: begin WRITE('Number? '); READLN(NUMBER); end
* if-statement: if A > 3 then WRITELN(A) else WRITELN("NOT YET") end
* switch-statement: switch (c) { case 'a': alert(); break; case 'q': quit(); break; }
* while-loop: while NOT EOF DO begin READLN end
* do-loop: do { computation(&i); } while (i < 10);
* for-loop: for A:=1 to 10 do WRITELN(A) end

Expressions

In most languages statements contrast with expressions in that statements do not return results and are executed solely for their side effects, while expressions always return a result and often do not have side effects at all. Among imperative programming languages, Algol 68 is one of the few in which a statement can return a result. In languages which mix imperative and functional styles, such as the Lisp family, the distinction between expressions and statements is not made: even expressions executed in sequential contexts solely for their side effects and whose return values are not used are considered 'expressions'. In purely functional programming, there are no statements; everything is an expression.

Programming languages

The syntax and semantics of statements is specified by the definition of the programming language. Most programming languages do not allow new statements to be created during program execution (Snobol 4 is a language that does), or existing statements to be modified (Lisp is well known for supporting self modifying code).

ee also

* Control flow
* Expression (contrast)
* Comparison of Programming Languages - Statements


Wikimedia Foundation. 2010.

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

Look at other dictionaries:

  • Statement — may refer to:*Press statement, a statement issued to the news media *statement (logic) that is either true or false *Sentence (linguistics), a type of sentence *Statement (programming), an instruction to execute something that will not return a… …   Wikipedia

  • Programming language — lists Alphabetical Categorical Chronological Generational A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that… …   Wikipedia

  • Programming paradigm — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concu …   Wikipedia

  • Statement analysis — is a learned technique, utilised to examine a person s words todetect for concealed information, missing information and whether the information that person provided is true or false. Anytime someone who is lying or withholding sensitive… …   Wikipedia

  • Statement block — In computer programming, a statement block (or code block) is a section of code which is grouped together, much like a paragraph; such blocks consist of one, or more, statements. Statement blocks help make code more readable by breaking up… …   Wikipedia

  • statement — /stayt meuhnt/, n. 1. something stated. 2. a communication or declaration in speech or writing, setting forth facts, particulars, etc. 3. a single sentence or assertion: I agree with everything you said except for your last statement. 4. Com. an… …   Universalium

  • statement — state·ment || steɪtmÉ™nt n. something stated, declaration; allegation; official account; printed record of account activity; instruction written in a high level programming language (Computers) …   English contemporary dictionary

  • Expression (programming) — An expression in a programming language is a combination of values, variables, operators, and functions that are interpreted ( evaluated ) according to the particular rules of precedence and of association for a particular programming language,… …   Wikipedia

  • Comparison of programming languages (syntax) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Comparison of programming languages (basic instructions) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

Share the article and excerpts

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