C++ for ENSC 151

What is a control statement

  • Helps control the program
    • order and such
  • Sequence

    • Sequence structure

      • statements execute one after another
  • Selection

    • if
    • if else
    • switch
  • Iteration

    • while
    • do while
    • for

Selection Structure

  • IF Statement

    • used for single selection

      • selects action if condition is TRUE
      • skips if false
  • IF else statement

    • used for double selection

      • selects action if true
      • skips to next action if false
  • Switch statement

    • used for multiple selection

      • selects one of many actions depending on condition
  • Break

    • immediate exit from current statement
  • Continue

    • skips the remaining statements in the loop body and goes with the next iteration

Iteration structure

  • Loops Statements

    • Performs statements repeatedly while true

  • While and for loops

    • if action initially true:

      • perform action zero or more times
    • If condition initially false

      • action is not executed
  • Do while:

    • While loop

      • test continuation statement before executing loop body
    • Do while loop

      • tests the loop continuation statement after executing the loops body
      • do statement executes before checking the while condition, continues until while is false