Categories of Control Flow Constructs - PowerPoint PPT Presentation

About This Presentation
Title:

Categories of Control Flow Constructs

Description:

Categories of Control Flow Constructs Sequencing order of expressions and statements Selection if, else, switch Iteration loops Procedural abstraction – PowerPoint PPT presentation

Number of Views:71
Avg rating:3.0/5.0
Slides: 7
Provided by: Christo598
Category:

less

Transcript and Presenter's Notes

Title: Categories of Control Flow Constructs


1
Categories of Control Flow Constructs
  • Sequencing
  • order of expressions and statements
  • Selection
  • if, else, switch
  • Iteration
  • loops
  • Procedural abstraction
  • Recursion
  • Concurrency
  • Exception handling and speculation
  • Nondeterminacy

2
Expressions vs. Statements
  • It is useful to differentiate expressions vs.
    statements
  • Statements (e.g., assignment) have side effects
    but usually do not return a value (C doesnt
    follow this strictly)
  • Expressions (e.g., right hand side of a
    statement) provide a value but usually dont have
    side effects (again except C)
  • Expression syntax may be prefix, infix, postfix
  • Prefix and postfix dont require parentheses for
    precedence
  • Comparison to procedures and functions
  • Operands are viewed as arguments or actual
    parameters
  • Referential transparency assumes no side effects
  • Side effects may change control flow as well as
    values
  • Some statements mimic complete control constructs
  • E.g., conditional operator in C acts like
    if/else construct

3
Structured vs. Unstructured Control Flow
  • Goto considered too low level
  • Still available in some languages
  • Rarely necessary, often better to use other
    features instead
  • E.g., break and continue statements in C
  • Many languages offer structured alternatives
  • E.g., break to exit a loop or a selected branch
    in C
  • E.g., continue to skip the rest of an iteration
    in C
  • Return and multi-level return
  • Return may set a value and also transfer control
    to caller
  • Multi-level return (or exception) may unwind
    farther
  • Continuations capture a context for further
    execution
  • E.g., to defer part of the execution until later

4
Sequencing
  • Ordering of statements
  • Happens-before relationship in control flow
  • Particularly important when thinking about
    concurrency
  • Data dependences
  • Previous write (store) to a variable (location)
    seen by subsequent read (load) instruction(s)
  • Compound statements
  • A block of statements is used in place of a
    single statement

5
Selection
  • If statements (e.g., in C)
  • If statement evaluates expression (not
    necessarily Boolean)
  • If true (non-zero) executes statements in its
    first block
  • Otherwise executes else block if one was provided
  • Can next if statements, so else associates with
    most recent If that does not already have an else
    part
  • Switch (case) statements
  • Condense if/else logic into cases of an ordinal
    expression
  • Default blocks (no case matches)
  • Breaks, fall through can be used to emulate
    ranges of cases

6
Todays Studio Exercises
  • Well code up ideas from Scott Chapter 6.1-6.4
  • Looking at expressions, statements, sequencing,
    selection
  • Next time well look at iteration, recursion,
    non-determinacy
  • Todays exercises are again in C
  • C allows us to explore control flow issues for
    statements
  • Functional languages rely more on function calls
    for control
  • Please take advantage of the on-line tutorial and
    reference manual pages that are linked on the
    course web site
  • As always, please ask us for help as needed
  • When done, email your answers with subject line
    Control Flow Studio I to cse425_at_seas.wustl.edu
Write a Comment
User Comments (0)
About PowerShow.com