• Flow of control - the order in which the computer executes statements in a program
  • Control Structure - A statement used to alter the normally sequential flow of controll
  • Selection
    • Look at a conditional statement
    • Take one branch if the statement is true
    • (Possibly) take another branch if the statement is false.
  • New Datatype BOOL
    • George Bool 1815, see page 213
    • Not a type in C, see box 204-205
    • Values are true or false
      bool Flag, Flag2;
      
      Flag = false;
      Flag2 = true;
      
    • Printing them out yields 0 for false and not 0 for true.
  • Logical expressions
  • These operators return a boolean.
    • == (equal to)
    • != (not equal)
    • > (greater)
    • < (less)
    • >= (greater equal)
    • <= (less than or equal)
  • Flag = 4 == 7;
  • x = 3; y = 2; Flag = x+3 <= y * 2;
  • Lexographical comparison of strings.
  • Flag = string1 > string2;
  • Logical Operators
    • or || - one or the other is true
    • and && - both are true
    • not ! - opposite of what we have.
    • AFlag = Name == "Dan Bennett" || Grade >= 89.5;
  • Short circuit evaluation
    • In a complex boolean expression, if the first part of an or is true, or the first part of an and is false, the evaluation can stop. (left to right)
  • Operator Precedence
    • ()
    • !, -a, +a
    • /, *, %
    • +, -
    • <, <=, >, >=
    • ==, !=
    • &&
    • ||
    • =
  • in general
    • Assignment operator returns the value that was assignend
    • constant compare variable
    • a == 3 // not good, if you forget a = you have an assignment
    • 3 == a //is better
    • Flag = a = 0;
  • Dont compare floats directly - roundoff error.
    • x = .1;
    • Flag = x == .1; // flag will be false
    • Flag = fabs(x-.1) < .0000001; // flag will be true