C++ for ENSC 151

What is a control statment

  • Helps control the program
    • order and such
  • Sequence

    • Sequence structure

      • statments 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 on 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

    • Preforms statements repeatedly while true

  • While and for loops

    • if action initially true:

      • prefrom 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 statment executes before checking the while condition, contiues until while is false