C++ Book


Summary

In this chapter, you should have learned the following concepts:

  • You can use the truth or falsity of an expression to branch to (or skip) sections of code.
  • You can represent truth or falsity with the keywords, ‘true’ and ‘false’
  • You can evalute any value or expression for truth or falsity.
  • Any non-zero value can be interprect as ‘true’, while 0 can be interpreted as false.
  • A common way to create an expression to be evaluated as ‘true’ or ‘false’ is to compare values with the relational operator.
  • The ‘if’ statement tests an expression and executes a section of code only if the expression is ‘true’.
  • The ‘else’ clause of an ‘if’ statement specifies code that should be executed only if the expression tested if the ‘if’ statement is ‘false’.
  • The ‘switch’ statement tests a value that can be treated as an ‘int’ and executes a section of code labeled with the corresponding value.
  • The ‘default’ keyword, when used in a ‘switch’ statement, specifies code to be executed if the value tested in the ‘switch’ statement matches no listed values.
  • The ‘while’ loop executes a section of code if an expression is ‘true’ and repeats the code as long as the expression is ‘true’.
  • A ‘do’ loop executes a section of code and then repeats the code as long as the expression is ‘true’.
  • Used in a loop, the ‘break’ statement immediately ends the loop.
  • Used in a loop, the ‘continue’ statement immediately ends the loop.
  • The && (AND) operator combines two simpler expressions to create a new expression that is ‘true’ if either simpler expression is ‘true’.
  • The   (OR) operator combines two simpler expressions to create a new expression that is ‘true’ if either simpler expression is ‘true’.
  • The ! (NOT) operator creates a new expressions that is the opposite truth value of the original.
  • The game loop is a generalized representation of the flow of events in a game, the core of which repeats.
  • The file ‘cstdlib’ contains functions that deal with generations random numbers.
  • The function ‘srand()’, defined in ‘cstdlib’, seeds the random number generator.
  • The function ‘rand()’, defined in ‘cstdlib’, returns a random number.