Control Flow

In computer science, control flow (or alternatively, flow of control) refers to the order in which the individual statements, instructions or function calls of an imperative or a declarative program are executed or evaluated.

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 functional languages, functions and language constructs exist to achieve the same result, but they are not necessarily called control flow statements.

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).

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. Self-modifying code can also be used to affect control flow through its side effects, but does not usually involve an explicit control flow statement (an exception being the ALTER verb in COBOL).

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).

Read more about Control FlowMinimal Structured Control Flow, Control Structures in Practice, Loops, Loop Sublanguage, Structured Non-local Control Flow, Proposed Control Structures

Other articles related to "control flow, control, flow":

Control Flow - Proposed Control Structures - Multiple Early Exit/exit From Nested Loops
... When some event does occur, the relevant action is carried out, and then control passes just after endexit ...
Object-oriented Programming - Design Patterns - OOP and Control Flow
... Transparent representation of the control flow had no priority and was meant to be handled by a compiler ... relevance of parallel hardware and multithreaded coding, developer transparent control flow becomes more important, something hard to achieve with OOP ...
Definite Assignment Analysis - The Analysis
... We supply data-flow equations that define the values of these functions on various expressions and statements, in terms of the values of the functions on their syntactic subexpressions ... over the abstract syntax tree and uses the data-flow equations to migrate information between the sets until a fixed point can be reached ... The algorithm is complicated by the introduction of control-flow jumps like goto, break, continue, return, and exception handling ...
Control Flow Diagram
... A control flow diagram (CFD) is a diagram to describe the control flow of a business process, process or program ... Control flow diagrams were developed in the 1950s, and are widely used in multiple engineering disciplines ... one of the classic business process modeling methodologies, along with flow charts, data flow diagrams, functional flow block diagram, Gantt charts, PERT diagrams, and IDEF ...
Instruction-level Parallelism
... A commonly used form of speculative execution is control flow speculation where instructions past a control flow instruction (e.g ... a branch) are executed before the target of the control flow instruction is determined ... Branch prediction which is used to avoid stalling for control dependencies to be resolved ...

Famous quotes containing the words flow and/or control:

    By the flow of the inland river,
    Whence the fleets of iron have fled,
    Where the blades of the grave-grass quiver,
    Asleep are the ranks of the dead:—
    Francis Miles Finch (1827–1907)

    To try to control a nine-month-old’s clinginess by forcing him away is a mistake, because it counteracts a normal part of the child’s development. To think that the child is clinging to you because he is spoiled is nonsense. Clinginess is not a discipline issue, at least not in the sense of correcting a wrongdoing.
    Lawrence Balter (20th century)