Chapter 8 Flashcards

(31 cards)

1
Q

What is the definition of control structure?

A

A control structure is a control statement and the collection of statements whose execution it controls.

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

What did Böhm and Jocopini prove about flowcharts?

A

Böhm and Jacopini proved that all algorithms that can be expressed by flowcharts can be coded in a programming language with only two control statements: one for choosing between two control flow paths and one for logically controlled iterations.

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

What is the definition of block?

A

A block is a sequence of code delimited by either braces or the do and end reserved words.

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

What is/are the design issue(s) for all selection and iteration control statements?

A

The design issue for all selection and iteration control statements is whether the control structure should have multiple entries.

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

What are the design issues for selection structures?

A

The design issues for selection structures are:
- What is the form and type of the expression that controls the selection?
- How are the then and else clauses specified?
- How should the meaning of nested selectors be specified?

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

What is unusual about Python’s design of compound statements?

A

Python uses indentation to specify compound statements.

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

Under what circumstances must an F# selector have an else clause?

A

An F# selector must have an else clause if the if expression returns a value.

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

What are the common solutions to the nesting problem for two-way selectors?

A

The common solutions are to require the inner if to be in a compound statement or to use special ending reserved words like end if.

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

What are the design issues for multiple-selection statements?

A

The design issues for multiple-selection statements are:
- 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?

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

Between what two language characteristics is a trade-off made when deciding whether more than one selectable segment is executed in one execution of a multiple selection statement?

A

The trade-off is between reliability and flexibility.

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

What is unusual about C’s multiple-selection statement?

A

C’s multiple-selection statement does not provide implicit branches at the end of its code segments, allowing control to flow through more than one selectable code segment on a single execution.

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

On what previous language was C’s switch statement based?

A

C’s switch statement is modeled on the multiple-selection statement in ALGOL 68.

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

Explain how C#’s switch statement is safer than that of C.

A

C# has a static semantics rule that disallows the implicit execution of more than one segment by requiring every selectable segment to end with an explicit unconditional branch statement.

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

What are the design issues for all iterative control statements?

A

The design issues for all iterative control statements are:
- How is the iteration controlled?
- Where should the control mechanism appear in the loop statement?

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

What are the design issues for counter-controlled loop statements?

A

The design issues for counter-controlled loop statements are:
- What are the type and scope of the loop variable?
- Should it be legal for the loop variable or loop parameters to be changed in the loop, and if so, does the change affect loop control?
- Should the loop parameters be evaluated only once, or once for every iteration?

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

What is a pretest loop statement? What is a posttest loop statement?

A

A pretest loop statement is one where the test for loop completion occurs before the loop body is executed.

A posttest loop statement is one where it occurs after the loop body is executed.

17
Q

What is the difference between the for statement of C++ and that of Java?

A

The loop control expression in Java’s for statement is restricted to boolean, whereas in C++ it can be arithmetic or boolean.

18
Q

In what way is C’s for statement more flexible than that of many other languages?

A

C’s for statement is more flexible because its expressions can include multiple statements, allowing multiple loop variables of any type, and variables in the expressions can be changed in the loop body.

19
Q

What does the range function in Python do?

A

The range function returns a list of numbers based on one, two, or three parameters, often used to iterate over a sequence in for loops.

20
Q

What contemporary languages do not include a goto?

A

Contemporary languages that do not include a goto are Java, Python, and Ruby.

21
Q

What are the design issues for logically controlled loop statements?

A

The design issues for logically controlled loop statements are:
- Should the control be pretest or posttest?
- Should the logically controlled loop be a special form of a counting loop or a separate statement?

22
Q

What is the main reason user-located loop control statements were invented?

A

The main reason user-located loop control statements were invented is to fulfill a common need for goto statements through a highly restricted branch statement.

23
Q

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

A

The design issues for user-located loop control mechanisms are:
- 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?

24
Q

What advantage does Java’s break statement have over C’s break statement?

A

Java’s break statement can be labeled to exit multiple nested loops, whereas C’s break exits only the innermost loop.

25
What are the differences between the break statement of C++ and that of Java?
C++’s break exits only one loop, while Java’s break can be labeled to exit enclosing loops as well.
26
What is a user-defined iteration control?
A user-defined iteration control is a statement and its iterator provided by the author of a data abstraction to iterate over user-defined data structures, common in object-oriented programming.
27
What Scheme function implements a multiple selection statement?
The COND function implements a multiple selection statement in Scheme.
28
How does a functional language implement repetition?
A functional language implements repetition using recursion.
29
How are iterators implemented in Ruby?
Iterators in Ruby are implemented as methods that take blocks, which are anonymous functions passed as parameters.
30
What language predefines iterators that can be explicitly called to iterate over its predefined data structures?
PHP predefines iterators like current, next, prev, and reset that can be explicitly called to iterate over arrays.
31
What common programming language borrows part of its design from Dijkstra’s guarded commands?
Ada borrows part of its design from Dijkstra’s guarded commands.