Statements

The actions that a program takes are expressed in statements. Common actions include declaring variables, assigning values, calling routines, looping through collections, and branching to one or another block of code, depending on a given condition. The order in which statements are executed in a program is called the flow of control or flow of execution. The flow of control may vary every time that a program is run, depending on how the program reacts to input that it receives at run time.

A statement can consist of a single line of code that ends in a semicolon, or a series of single-line statements in a block. A statement block is enclosed in {} brackets and can contain nested blocks. A statement in programming language theory usually results in something called a side effect. A side effect, loosely defined, is a permanent change of state in a program, such as modifying a global variable or changing the buffer stack.

Types of statement:

  • declaration
  • control

Here are some statements:

var x: int;                            // Also a declaration.
x = 0;                                 // Also an assignment.
if(expr) { /*...*/ }                   // This is why it's called an "if-statement".
for(expr) { /*...*/ }                  // For-loop.