Chapter 5 Flashcards
What is the 4 step process in constructing a while loop?
1) Identify the actions that must be repeated in the loop
2) Identify the boolean expression that must be true in order for the while statement to run
3) Assemble the while loop
4) Add additional actions before or after the loop to complete the solution.
Define 5 characteristics of a temporary variable
1) Also called local variables
2) Occur inside a method
3) Store a value until the end of the method
4) Have a value type
5) Must be given an initial value
Define scope
The region of the program in which a variable may be used
Define 4 types of legal expressions
1) Literal values
2) Variables
3) Methods
4) Operators whose operands are legal expressions
What loop do you use if a parameter refers to the number of times the loop will execute
a count-down loop or a for loop
What loop do you use if the number of times the loop will execute is known before the loop is entered?
A for loop
What loop do you use if the loop might execute zero times?
A while loop
What loop do you use if the loop has a single test that is relatively simple that appears at the top of the loop?
A while loop
What loop do you use if the loop always executes at least once?
A do-While loop
What loop do you use if the loop executes an extra half time?
Use a while-true loop
What loop do you use if the loop had multiple exit tests?
A while-true loop
What is short-circuit evaluation?
if the first evaluation is false in the series of Boolean expressions, it will skip the second expression