Statement (programming)
Encyclopedia : S : ST : STA : 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 (eg, 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.
The following are the major generic kinds of statements with examples in typical imperative languages:
definitions and declarations
- definition:
TYPE SALARY = INTEGER - declaration:
VAR A:INTEGER
- assignment:
A := A + 1 - call:
CLEARSCREEN() - return:
return 5; - goto:
goto 1 - assertion:
assert(ptr != NULL);
- 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) - while-loop:
while NOT EOF DO begin READLN end - do-loop:
do while (i < 10); - for-loop:
for A:=1 to 10 do WRITELN(A) end
The syntax and semantics of statements is usually specified in the definition of the programming language and cannot be changed in a program. Only a few programming languages allow user defined statements or overloading of statements.
Typical programming languages with statements are Ada, ALGOL, BASIC, C, C++, COBOL, Eiffel, Fortran, Java, JavaScript, Modula, Oberon, Pascal, Perl, PL/I, Python, REXX, Ruby, Seed7, Simula and Tcl.
See also
- Control flow
- Expression (contrast)
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
