All Topics  
Statement (programming)

 

   Email Print
   Bookmark   Link






 

Statement (programming)



 
 
In computer programming
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
 a statement can be thought of as the smallest standalone element of an imperative programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
. A program is formed by a sequence of one or more statements. A statement will have internal components (e.g., expressions
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
).

Many languages (e.g. C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
) make a distinction between statements and definitions, with a statement only containing executable code and a definition declaring an identifier
Identifier

In computer science, Identifiers are Lexical Token s that name entity. The concept is analogy to that of a "name". Identifiers are used extensively in virtually all information processing systems....
. A distinction can also be made between simple and compound statements; the latter may contain statements as components.

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



ost languages, statements contrast with expression
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
s 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.






Discussion
Ask a question about 'Statement (programming)'
Start a new discussion about 'Statement (programming)'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computer programming
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
 a statement can be thought of as the smallest standalone element of an imperative programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
. A program is formed by a sequence of one or more statements. A statement will have internal components (e.g., expressions
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
).

Many languages (e.g. C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
) make a distinction between statements and definitions, with a statement only containing executable code and a definition declaring an identifier
Identifier

In computer science, Identifiers are Lexical Token s that name entity. The concept is analogy to that of a "name". Identifiers are used extensively in virtually all information processing systems....
. A distinction can also be made between simple and compound statements; the latter may contain statements as components.

Kinds of statements

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

Simple statements

  • assignment
    Assignment (computer science)

    In computer science the assignment statement sets or re-sets the Value stored in the storage location denoted by a variable name. In most imperative programming computer programming languages the assignment statement is one of the basic Statement s....
    : A := A + 1
  • call
    Subroutine

    In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
    : CLEARSCREEN
  • return
    Return statement

    In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after where the subroutine was called ? known as its return address....
    : return 5;
  • goto
    GOTO

    GOTO is a statement found in many computer programming languages. It is a combination of the English words wiktionary:go and wiktionary:to....
    : goto 1
  • assertion
    Assertion (computing)

    In computer programming, an assertion is a First-order logic placed in a program to indicate that the developer thinks that the predicate is always true at that place....
    : assert(ptr != NULL);


Compound statements

  • statement block
    Statement block

    In computer programming, a statement block is a section of computer code which is grouped together, much like a paragraph; such blocks consist of one, or more, statement ....
    : begin WRITE('Number? '); READLN(NUMBER); end
  • if-statement
    Conditional statement

    In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified condition evaluates to true or false ....
    : if A > 3 then WRITELN(A) else WRITELN("NOT YET"); end
  • switch-statement
    Switch statement

    In computer programming, a switch statement is a type of control Statement that exists in most modern imperative programming languages . Its purpose is to allow the value of a variable or expression to control the flow of program execution....
    : switch (c)
  • while-loop
    While loop

    In most computer programming languages, a while loop is a Control flow statement that allows code to be executed repeatedly based on a given Boolean datatype condition....
    : while NOT EOF DO begin READLN end
  • do-loop
    Do while loop

    In most computer programming languages, a do while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean datatype condition....
    : do while (i < 10);
  • for-loop
    For loop

    In computer science a for loop is a programming language statement which allows code to be repeatedly execution . A for loop is classified as an iteration statement....
    : for A:=1 to 10 do WRITELN(A) end


Expressions

In most languages, statements contrast with expression
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
s 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. Among imperative programming languages, Algol 68
ALGOL 68

ALGOL 68 is an imperative programming computer programming programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics....
 is one of the few in which a statement can return a result. In languages which mix imperative and functional
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 styles, such as the Lisp
Lisp programming language

Lisp is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older....
 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
Purely functional

Purely functional is a term in computing used to describe algorithms, data structures or programming languages that exclude destructive modifications ....
 programming, there are no statements; everything is an expression.

Programming languages

The syntax and semantics of statements is specified by the definition of the programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
. Most programming languages do not allow new statements to be created during program execution (Snobol 4 is a language that does), or existing statements to be modified (Lisp is well known for supporting self modifying code).

See also

  • Control flow
    Control flow

    In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated....
  • Expression
    Expression (programming)

    An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
     (contrast)
  • Comparison of Programming Languages - Statements
    Comparison of programming languages (syntax)

    ExpressionsProgramming language Expression s can be broadly classifiedin three classes:prefix notation* Lisp infix notation...