SlideServe
Menu
Préférences
© SlideServe · v2026

Statement-level Control Structures

katen avatar
19 diapositives · 460 Views · Jul 18, 2014

Statement-level Control Structures. The Flow of Control Among Statements. Introduction. Selection Statements Iterative Statements Unconditional Branching Guarded Commands. Introduction. Control statements provide two very important means of making programs flexible and powerful.

Statement-level Control Structures - slide 1
01 / 19Statement-level Control Structures
1 / 17

Télécharger la présentation

Statement-level Control Structures
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Statement-level Control Structures The Flow of Control Among Statements

  2. Introduction • Selection Statements • Iterative Statements • Unconditional Branching • Guarded Commands

  3. Introduction • 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. INTRODUCTION (Continued) • 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. Control Statement Design Issues • 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. Selection Statements

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

  8. Issues in Selection Statements • 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. Iterative Statements

  10. Iterative Statements • Counter-Controlled Loops • Logically Controlled Loops • User-Located Loop Control Mechanisms • Iteration Based on Data Structures

  11. Unconditional Branching

  12. Unconditional Branching • 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. Examples of Unconditional Branching Statements • GOTO • Switch • User-Controlled Loop Control Statements

  14. Guarded Commands

  15. Guarded Commands • 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 • 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. Conclusions • 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. Conclusions (continued) • 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. SUMMARY • There are several different categories of control structures. • Selection • Multiple selection • Iterative • Unconditional branching • Looping structures vary among languages • Do • For • Foreach