Statement (programming) Article Index for
Statement
Website Links For
Statement
 

Information About

Statement (programming)




Many languages (eg, C ) make a distiction between statements and definitions, with a statement only containing executable code and a definition declaring an identifier.

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

  • definition: TYPE SALARY = INTEGER

  • Declaration : VAR A:INTEGER

  • Assignment : A := A + 1

  • sequence: A := A + 1; WRITELN(A)

  • 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

  • Call : CLEARSCREEN()

  • Return : return 5;

  • Goto : goto 1

  • Assertion : assert(ptr != NULL);


In most languages statements contrast with Expression s in that the former do not return results and are executed solely for their Side Effect s, while the latter 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'.

The syntax and semantics of statements is usually specified in the definition of the Programming Language and cannot be changed in a program. Only 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