Eight Major Categories of Control-Flow Mechanisms
Control-flow is an ordering of the program execution. It decides which task should be completed first, which task should be completed second and so on.
The eight major categories to organize the control- flow mechanisms are:
1. Sequencing: Statements are executed in a specific predefined order, most probably in the order of their appearance in the program code.
2. Selection (or alternation): Depending upon some run-time condition, a choice between two or more than two statements (or expressions) is to be made. Examples of selection constructs include if and case (switch) statements.
3. Iteration: A given code segment is to be executed repeatedly. This needs to be done either a certain number of times (for example in case of for/do loops), or until a run-time condition turns out to be true (for example, in case of while, and repeat loops).
4. Procedural abstraction: A complex collection of control constructs (a subroutine) are encapsulated to be treated as a single unit. The collection is usually subjected to parameterization. Procedural abstraction is also used in case same code is needed in many sections of a program.
5. Recursion: An expression is directly or indirectly defined in terms of itself. Recursion is also known as self-referential or self-calling subroutines.
6. Concurrency: Two or more program segments are executed or evaluated at the same time. The execution may be either in parallel on separate processors, or may be interleaved on a single processor.
7. Exception handling and speculation: A program segment is executed assuming that some expected condition will be true. But, if that condition is not fulfilled (that is, it turns out to be false) then
i. In the case of exception handling, execution branches out to an exception handler that executes in place of the remainder of the protected fragment of code,
ii. In the case of speculation, the exception handler is executed in place of the entire protected code fragment.
8. Non-determinacy: The ordering of statements or expressions is not specified. This is done to imply that any of the alternatives will lead to correct results.
Chegg is one of the leading providers of homework help for college and high school students. Get homework help and answers to your toughest questions in math, calculus, algebra, physics, chemistry, science, accounting, English and more. Master your homework assignments with our step-by-step solutions to more than 3000 textbooks. If we don't support your textbook, don't worry! You can ask a homework question and get an answer in as little as two hours. With Chegg, homework help is just a few clicks away.