What is the definition of control structure?
A control structure is a control statement and the collection of statements whose execution it controls.
What did Böhm and Jocopini prove about flowcharts?
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.
What is the definition of block?
A block is a sequence of code delimited by either braces or the do and end reserved words.
What is/are the design issue(s) for all selection and iteration control statements?
The design issue for all selection and iteration control statements is whether the control structure should have multiple entries.
What are the design issues for selection structures?
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?
What is unusual about Python’s design of compound statements?
Python uses indentation to specify compound statements.
Under what circumstances must an F# selector have an else clause?
An F# selector must have an else clause if the if expression returns a value.
What are the common solutions to the nesting problem for two-way selectors?
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.
What are the design issues for multiple-selection statements?
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?
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?
The trade-off is between reliability and flexibility.
What is unusual about C’s multiple-selection statement?
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.
On what previous language was C’s switch statement based?
C’s switch statement is modeled on the multiple-selection statement in ALGOL 68.
Explain how C#’s switch statement is safer than that of C.
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.
What are the design issues for all iterative control statements?
The design issues for all iterative control statements are:
- How is the iteration controlled?
- Where should the control mechanism appear in the loop statement?
What are the design issues for counter-controlled loop statements?
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?
What is a pretest loop statement? What is a posttest loop statement?
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.
What is the difference between the for statement of C++ and that of Java?
The loop control expression in Java’s for statement is restricted to boolean, whereas in C++ it can be arithmetic or boolean.
In what way is C’s for statement more flexible than that of many other languages?
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.
What does the range function in Python do?
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.
What contemporary languages do not include a goto?
Contemporary languages that do not include a goto are Java, Python, and Ruby.
What are the design issues for logically controlled loop statements?
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?
What is the main reason user-located loop control statements were invented?
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.
What are the design issues for user-located loop control mechanisms?
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?
What advantage does Java’s break statement have over C’s break statement?
Java’s break statement can be labeled to exit multiple nested loops, whereas C’s break exits only the innermost loop.