Chapter 8 Flashcards
What is a control statement?
If, while, for, the word or boolean conjunction
What is a control structure?
The if, while, … including the block of code it runs. A set of control statements plus the body.
What is a two-way selection statement?
if ()
then…
else…
What are the design issues related to two-way selection statements?
-What is the form and type of the expression that controls the selection?
-How are the then and else clause specified?
-How should the meaning of nested selectors be specified?
How are nested selection statements handled in various languages?
-Java, C, C++, C# -> binds else to the nearest if statement, or use {}
-Ruby -> Use “end” to denote the end of each nested section
What is a multiple selection branch?
Allows for a selection between any number of statements or statement groups
What are the design issues related to multiple selection branches?
-What is the form and type of the expression that controls the selection?
-How are the selectable segments specified?
-Is execution flow through the structure restricted to include just a single selectable segment?
-How are the case values specified?
-How should unrepresented selector expression values be handled, if at all?
What are two different implementations of multiple selection branches?
-Switches
-Conds from Racket
What is an iterative structure?
A selection statement that repeatedly runs a block of code
What are the 3 main types of iterative structures?
Count controlled, logical controlled, user controlled. Or for, while, do-while.
What are the design decisions for these main types of iterative structures?
-Count controlled:
When is the loop variable evaluated?
What is the scope of the loop variable?
Can the user change the loop variable?
-Logic controlled:
Should the loop be pre or post test?
Should logically controlled loops use a different key word?
-User controlled:
Should the conditional mechanism be an integral part of the exit?
Should only one loop body be exited, or can enclosing loops also be exited?
What is an unconditional branch command?
Goto
Why is the goto command so dangerous?
-Difficult to trace
-Hard to write
-Leads to error-prone code