Lecture 9 Flashcards
What are the three levels of control flow?
- Within expressions
- Among program units
- Among program statements
How did control statements evolve in the 1960s?
FORTRAN I’s control statements were hardware-based.
1960s research led to the realization that all flowcharts can be coded with two-way selection and pretest logical loops.
What is a control structure?
A control structure includes a control statement and the statements it controls.
What are the two general categories of selection statements?
- Two-way selectors
- Multiple-way selectors
What are the design issues for two-way selection statements?
- Form and type of the control expression.
- Specification of then and else clauses.
- Handling of nested selectors.
What is a drawback of FORTRAN’s IF statement?
It uses negative logic, which is bad for readability.
How does ALGOL 60 specify then and else clauses?
if (boolean_expr)
then statement
else statement
How do Java and ALGOL 60 handle nested selectors?
- Java: Else associates with the nearest if.
ALGOL 60: Disallows direct nesting.
How do FORTRAN 90 and Ada enhance readability in nested selectors?
By using closing special words like end if.
What are the design issues for multiple-way selection statements?
- Form and type of the control expression.
- Specification of selectable segments.
- Execution flow restrictions.
- Handling of unrepresented expression values.
What is a three-way selector in FORTRAN, and what is its use?
The Arithmetic IF, used for problems with three evaluative values (less than, equal to, greater than zero).
Describe the Pascal case structure.
case expression of
constant_list_1: statement_1;
…
constant_list_n: statement_n
end
What are the key design choices for the switch statement in C/C++/Java?
Control expression must be an integer.
Selectable segments can be statements, blocks, or compounds.
No implicit branch, must use break.
Default clause for unrepresented values.
How does Ada’s case statement enhance reliability?
By requiring exhaustive constant lists, often using an others clause.
What are the general design issues for iterative statements?
- How is iteration controlled?
- Where is the control mechanism in the loop?