Statements
In short: A single, complete action in code that causes something to happen — e.g. assigning a variable, calling a method, or starting a loop. A program consists of a sequence of such statements.
In more detail: Unlike an expression (which evaluates to a value, e.g. 2 + 3), a statement causes an action and itself returns no reusable value. In most languages, statements are separated from each other by a semicolon or a line break and executed one after another in the order they appear in the code — unless a control structure like if…else or a loop changes the flow.
In Depth
The difference between an expression and a statement can be shown well with the following example:
2 + 3 # expression - evaluates to 5, but otherwise causes nothing
x = 2 + 3 # statement - performs an assignment (the action of "setting x")A statement “does something” (changes the program state, prints something, calls a function with a side effect), while a pure expression is only evaluated to a value, with no effect of its own. In practice this often blends together — a function-call statement like calculateAndSave(x) itself contains expressions again (the arguments), and some languages (e.g. modern functional or scripting languages) blur the boundary between the two even further, by treating almost everything as an expression.
Typical statement categories in most languages:
- Declarations: creating a new variable/function/class
- Assignments: giving an existing variable a new value
- Control-flow statements:
if/else, loops,return,break/continue - Expression statements: a function call whose return value is ignored, but whose side effect (e.g. printing something) is intended
The order in which statements normally run — top to bottom, one after another — is called sequential control flow. Control structures like if…else or loops deliberately break this rigid order, by skipping, repeating, or conditionally executing certain statements — this is exactly what turns a pure sequence of instructions into an actually “intelligent” program.
See also: Print Variables, if…else