The following are some of the major generic kinds of statements, pseudocoded. These pseudocoded statements have an immediate corresponding syntax in any typical imperative language like Pascal, C, Fortran etc.:
Conditional |: if A > 3 then WRITELN else WRITELN; end
Switch statement|: switch
While loop|: while NOT EOF do begin READLN end
': with open as f: use
The appearance of statements shapes the look of programs. Programming languages are characterized by the type of statements they use. 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 or not at all. Technically such statement parameters are call-by-name parameters. Call-by-name parameters are evaluated when needed. When call-by-name parameters are available a statement like behaviour can be implemented with subroutines. 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.
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. For example:
Among imperative programming languages, Algol 68 is one of the few in which a statement can return a result. In languages that 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. This distinction is frequently observed in wording: a statement is executed, while an expression is evaluated. This is found in the exec and eval functions found in some languages: in Python both are found, with exec applied to statements and eval applied to expressions. A statement is an instruction that the Python interpreter can execute. We have only seen the assignment statement so far. Some other kinds of statements that we’ll see shortly are while statements, for statements, if statements, and import statements. An expression is a combination of values, variables, operators, and calls to functions. Expressions need to be evaluated. If you ask Python to print an expression, the interpreter evaluates the expression and displays the result.