Machine Control flow
Control flow
By
Ms. V.VENNILA, MCA.,M.Phil.,
Assistant Professor,
Bon Secours College for Women, Thanjavur.
Control flow
In computer science, control flow (or flow of control) is the order in which
individual statements, instructions or function calls of
an imperativeprogram are executed or evaluated. The emphasis on explicit
control flow distinguishes an imperative programming language from
a declarative programming language.
Within an imperative programming language, a control flow statement is a
statement that results in a choice being made as to which of two or more
paths to follow. For non-strict functional languages, functions and language
constructs exist to achieve the same result, but they are usually not termed
control flow statements.
A set of statements is in turn generally structured as a block, which in
addition to grouping, also defines a lexical scope.
Categories
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)
Minimal structured control flow
• In May 1966, Böhm and Jacopini published an article
in Communications of the ACM which showed that any program
with gotos could be transformed into a goto-free form involving
only choice (IF THEN ELSE) and loops (WHILE condition DO
xxx), possibly with duplicated code and/or the addition of
Boolean variables (true/false flags). Later authors showed that
choice can be replaced by loops (and yet more Boolean
variables).
• That such minimalism is possible does not mean that it is
necessarily desirable; after all, computers theoretically need
only one machine instruction(subtract one number from another
and branch if the result is negative), but practical computers
have dozens or even hundreds of machine instructions.
Loops
• A loop is a sequence of statements which is specified once but
which may be carried out several times in succession. The code
"inside" the loop (the body of the loop, shown below as xxx) is
obeyed a specified number of times, or once for each of a collection
of items, or until some condition is met, or indefinitely.
• In functional programming languages, such as Haskell and Scheme,
loops can be expressed by using recursion or fixed point
iteration rather than explicit looping constructs. Tail recursion is a
special case of recursion which can be easily transformed to
iteration.
Count – Controlled loops
• Main article: For loop
• Most programming languages have constructions for
repeating a loop a certain number of times. In most
cases counting can go downwards instead of upwards
and step sizes other than 1 can be used.
• FOR I = 1 TO N | for I := 1 to N do begin xxx | xxx
NEXT I | end; -------------------------------------------------
----------- DO I = 1,N | for ( I=1; I<=N; ++I ) { xxx | xxx
END DO | }
Thank you

Machine control flow

  • 1.
    Machine Control flow Controlflow By Ms. V.VENNILA, MCA.,M.Phil., Assistant Professor, Bon Secours College for Women, Thanjavur.
  • 2.
    Control flow In computerscience, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperativeprogram are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language. Within an imperative programming language, a control flow statement is a statement that results in a choice being made as to which of two or more paths to follow. For non-strict functional languages, functions and language constructs exist to achieve the same result, but they are usually not termed control flow statements. A set of statements is in turn generally structured as a block, which in addition to grouping, also defines a lexical scope.
  • 3.
    Categories The kinds ofcontrol 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)
  • 4.
    Minimal structured controlflow • In May 1966, Böhm and Jacopini published an article in Communications of the ACM which showed that any program with gotos could be transformed into a goto-free form involving only choice (IF THEN ELSE) and loops (WHILE condition DO xxx), possibly with duplicated code and/or the addition of Boolean variables (true/false flags). Later authors showed that choice can be replaced by loops (and yet more Boolean variables). • That such minimalism is possible does not mean that it is necessarily desirable; after all, computers theoretically need only one machine instruction(subtract one number from another and branch if the result is negative), but practical computers have dozens or even hundreds of machine instructions.
  • 5.
    Loops • A loopis a sequence of statements which is specified once but which may be carried out several times in succession. The code "inside" the loop (the body of the loop, shown below as xxx) is obeyed a specified number of times, or once for each of a collection of items, or until some condition is met, or indefinitely. • In functional programming languages, such as Haskell and Scheme, loops can be expressed by using recursion or fixed point iteration rather than explicit looping constructs. Tail recursion is a special case of recursion which can be easily transformed to iteration.
  • 6.
    Count – Controlledloops • Main article: For loop • Most programming languages have constructions for repeating a loop a certain number of times. In most cases counting can go downwards instead of upwards and step sizes other than 1 can be used. • FOR I = 1 TO N | for I := 1 to N do begin xxx | xxx NEXT I | end; ------------------------------------------------- ----------- DO I = 1,N | for ( I=1; I<=N; ++I ) { xxx | xxx END DO | }
  • 7.