Difference between revisions of "Control flow"
Karl Jones (Talk | contribs) |
Karl Jones (Talk | contribs) (→External links) |
||
(One intermediate revision by the same user not shown) | |||
Line 7: | Line 7: | ||
Within an [[Imperative programming|imperative programming language]], a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed. | Within an [[Imperative programming|imperative programming language]], a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed. | ||
− | For [[non-strict | + | For [[Non-strict programming language|non-strict programming languages]], functions and language constructs exist to achieve the same result, but they are not necessarily called control flow statements. |
== Categories of control flow == | == Categories of control flow == | ||
Line 37: | Line 37: | ||
* [[Declarative programming]] | * [[Declarative programming]] | ||
* [[Imperative programming]] | * [[Imperative programming]] | ||
+ | * [[Non-strict programming language]] | ||
== External links == | == External links == | ||
* [https://en.wikipedia.org/wiki/Control_flow Control flow] @ Wikipedia | * [https://en.wikipedia.org/wiki/Control_flow Control flow] @ Wikipedia | ||
+ | |||
+ | [[Category:Computer programming]] | ||
+ | [[Category:Computer science]] |
Latest revision as of 17:58, 21 April 2016
In computer science, control flow (or alternatively, flow of control) refers to the specification of the order in which the individual statements, instructions or function calls of an imperative program are executed or evaluated.
The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.
Contents
Description
Within an imperative programming language, a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed.
For non-strict programming languages, functions and language constructs exist to achieve the same result, but they are not necessarily called control flow statements.
Categories of control flow
The kinds of control flow statements supported by different languages vary, but can be categorized by their effect:
- Continuation at a different statement (unconditional branch or jump),
- Executing a set of statements only if some condition is met (choice - i.e., conditional branch),
- Executing a set of statements zero or more times, until some condition is met (i.e., loop - the same as conditional branch),
- Executing a set of distant statements, after which the flow of control usually returns (subroutines, coroutines, and continuations),
- Stopping the program, preventing any further execution (unconditional halt).
Blocks and lexical scope
A set of statements is in turn generally structured as a block, which in addition to grouping also defines a lexical scope.
Interrupts and signals
Interrupts and signals are low-level mechanisms that can alter the flow of control in a way similar to a subroutine, but usually occur as a response to some external stimulus or event (that can occur asynchronously), rather than execution of an 'in-line' control flow statement.
Machine language, assembly language
At the level of machine or assembly language, control flow instructions usually work by altering the program counter. For some CPUs the only control flow instructions available are conditional or unconditional branch instructions (also called jumps).
See also
- Computer program
- Computer science
- Declarative programming
- Imperative programming
- Non-strict programming language
External links
- Control flow @ Wikipedia