Lecture 9 Flashcards

1
Q

What are the three levels of control flow?

A
  1. Within expressions
  2. Among program units
  3. Among program statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How did control statements evolve in the 1960s?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a control structure?

A

A control structure includes a control statement and the statements it controls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two general categories of selection statements?

A
  1. Two-way selectors
  2. Multiple-way selectors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the design issues for two-way selection statements?

A
  1. Form and type of the control expression.
  2. Specification of then and else clauses.
  3. Handling of nested selectors.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a drawback of FORTRAN’s IF statement?

A

It uses negative logic, which is bad for readability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does ALGOL 60 specify then and else clauses?

A

if (boolean_expr)
then statement
else statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do Java and ALGOL 60 handle nested selectors?

A
  • Java: Else associates with the nearest if.

ALGOL 60: Disallows direct nesting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do FORTRAN 90 and Ada enhance readability in nested selectors?

A

By using closing special words like end if.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the design issues for multiple-way selection statements?

A
  1. Form and type of the control expression.
  2. Specification of selectable segments.
  3. Execution flow restrictions.
  4. Handling of unrepresented expression values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a three-way selector in FORTRAN, and what is its use?

A

The Arithmetic IF, used for problems with three evaluative values (less than, equal to, greater than zero).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe the Pascal case structure.

A

case expression of
constant_list_1: statement_1;

constant_list_n: statement_n
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the key design choices for the switch statement in C/C++/Java?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does Ada’s case statement enhance reliability?

A

By requiring exhaustive constant lists, often using an others clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the general design issues for iterative statements?

A
  1. How is iteration controlled?
  2. Where is the control mechanism in the loop?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Compare FORTRAN 90 and Pascal counter-controlled loops.

A
  • FORTRAN 90: Integer loop variable, parameters evaluated once.

Pascal: Ordinal type loop variable, parameters evaluated once, loop variable undefined after termination.

17
Q

What are the key design issues for logically-controlled loops?

A
  1. Pretest or posttest?
  2. Special case of counting loop statement or separate statement?
18
Q

What are the design issues for user-located loop control mechanisms?

A
  1. Should the conditional be part of the exit?
  2. Transfer control out of more than one loop?
19
Q

How does Perl handle iteration based on data structures?

A

With built-in iterators for arrays and hashes, using the foreach construct.

20
Q
A