Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Flow of Control Among Statements.  Selection Statements  Iterative Statements  Unconditional Branching  Guarded Commands.

Similar presentations


Presentation on theme: "The Flow of Control Among Statements.  Selection Statements  Iterative Statements  Unconditional Branching  Guarded Commands."— Presentation transcript:

1 The Flow of Control Among Statements

2  Selection Statements  Iterative Statements  Unconditional Branching  Guarded Commands

3  Control statements provide two very important means of making programs flexible and powerful.  Some way of allowing different control flow paths.  A way of allowing for the repeated execution of statements or groups of statements.  A control structure is defined as a control statement and the collection of statements whose execution it controls.

4  Bohm and Jacopini proved that all algorithms that can be diagrammed in a flowchart can be reproduced in a programming language with only the two previously mentioned control statements.  So why have more than these?

5  The one design issue which is common to all control and iteration structures is whether to allow multiple points of entry to the statement.  These multiple entry points are only possible in languages that allow for GOTO or statement labels.  Multiple exits from a control statement exist in most programming languages and they are not seen as a detriment either to readability or understanding.

6

7  Selection statements are grouped into two different categories.  Two-way control statements (if then)  n-way control statements

8  What type of expression controls the if statement  How are then and else clauses specified.  By curly braces.  With the keyword Then.  How should the meaning of nested selectors be specified.  Indention  Placed in a compound (Braces)  Using a reserved word to end the statement.

9

10  Counter-Controlled Loops  Logically Controlled Loops  User-Located Loop Control Mechanisms  Iteration Based on Data Structures

11

12  An unconditional branch statement transfers execution control to a specified location in the program.  Can be one of the most powerful statements in any language.  Leads to problems in readability since programs are not restricted to a traditional top to bottom flow of execution.  Can lead to higher maintenance costs and unreliability.

13  GOTO  Switch  User-Controlled Loop Control Statements

14

15  A new and different form of selection and loop statement recommended by Dijkstra  Supports correctness in development.  Constructs can be considered independently  Increased clarity in reasoning  Allows for nondeterminism  Enables program verification

16  Guarded commands consist of a boolean expression, the guard, and the statement or statements to be executed when it is found true.  Although it bears some resemblance to a multi- select statement, it differs in that any statement whose guard evaluates to true can be executed.

17  Although Bohm and Jacopini proved that only selection and pretest logical loops were absolutely necessary to follow an flow chart sequence, no modern language has taken the step to remove other control structures.  Additional control structures which have been suggested in the past may have not been included because doing so would increase the size and complexity of languages.

18  Control structures should be simple.  They should have one entrance although having more than one exit from a control structure is standard and is not seen as a hindrance to readability.  GOTO is regarded as evil, however many modern languages still allow it, including C#.

19  There are several different categories of control structures.  Selection  Multiple selection  Iterative  Unconditional branching  Looping structures vary among languages  Do  For  Foreach


Download ppt "The Flow of Control Among Statements.  Selection Statements  Iterative Statements  Unconditional Branching  Guarded Commands."

Similar presentations


Ads by Google