A statement is a programming language construct that constitutes an instruction to perform a specific task. It tells the computer to do something and is basically a single step in the sequence of steps that makes up the entire program.


To constitute a single step, a statement needs to be closed. Closing a statement indicates that it is complete and delimits it from the next statement.

Statements in many languages, including C++ and Java, are closed with semicolons and are formatted as follows:

instruction ;

where

instruction is the instruction to perform a specific task.
; closes the statement and delimits it from the next statement.

A statement declares an entity, evaluates and assigns an expression, controls the sequence of execution, or does nothing. Statements can be categorised in the following ways:

declaration statement

A declaration statement, often referred to simply as a declaration, specifies aspects of a variable or constant, such as its dimensions, identifier and type. It is used to announce the existence of a variable, constant or subroutine. This is important in some languages which require variables, constant and subroutines to be declared before use. Declarations are often made in header files, which are meant to be included in other files that reference and use these declarations.

By contrast, a definition defines what a variable, constant or subroutine actually is. For variables and constants, definitions assign bits to an area of memory that was reserved during the declaration. For functions, definitions supply the function body.

assignment statement

An assignment statement evaluates an expression and assigns its value to a variable or constant. It is formatted as follows:

variable = expression

where

variable is the variable or constant to which the value is assigned
= is the assignment operator .
expression is the expression that is evaluated.

For example, a = b + c is a statement that assigns the value of expression b + c to variable a.

Unlike in algebra, this statement does not mean that a equals b + c. This is read, "Assign the value of the sum of b plus c to a". The assignment operator assigns whatever is on the right side of the equal sign to whatever is on the left side.

flow-control statement

A flow-control statement determines flow of program execution.

Flow control refers to the order in which the individual statements in a program are executed. Normally statements are executed in order from top to bottom. A flow-control statement is an instruction that when executed can cause a change in the order of statement execution, causing the order to differ from the sequential order in which the statements are listed.

Flow-control statements include the following kind of statement:

return statement

A return statement causes execution to leave the current subroutine and resume at the point the subroutine was called. If the subroutine is a function , the return statement allows it to specify a return value to be passed back to the code that called the function . This return value can be assigned to a variable or constant. Its type is specified in the function declaration.

null statement

A null statement does nothing.

Statement Block

A statement block is a group of statements.

Statement blocks in many languages, including C++ and Java, are enclosed in braces {} as follows:

{ statements }

Statement blocks allow programmers to place a group of statements where otherwise they could only put one. For example if statements and loop statements are usually used with statement blocks for their bodies.


examples return statement GCC C++
Borland C++ Compiler
flow-control statement Java
declaration statement GCC C++
Borland C++ Compiler
Java
home Home Page