Concept of Programming Language Chapter: 8

REVIEW QUESTIONS

1.   What is the definition of control structure?

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

2.   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

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

There is only one design issue that is relevant to all of the selection and iteration control statements: Should the control structure have multiple entries? All selection and iteration constructs control the execution of code segments, and the question is whether the execution of those code segments always begins with the first statement in the segment.

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

An F# selector have an else clause when the if expression does return a value

9.   What are the design issues for multiple-selection statements?

• 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?

14.  What are the design issues for all iterative control statements?

• How is the iteration controlled?
• Where should the control mechanism appear in the loop statement?

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

• 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?

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

Pretest loop statements are set of statements to be executed repeatedly in which the test for loop completion occurs before the loop body is executed

Posttest loop statements are set of statements to be executed repeatedly in which the test for loop completion occurs after the loop body is executed

21.  What are the design issues for logically controlled loop statements?

• Should the control be pretest or posttest?
• Should the logically controlled loop be a special form of a counting loop or a separate statement?

26.  What is a user-defined iteration control?

A user-defined iteration control is the one that issues a special call to the iterator, in which the iterator is called at the beginning of each iteration, and each time it is called, the iterator returns an element from a particular data structure in some specific order.

 

PROBLEM SET

1.   What design issues should be considered for two-way selection statements?

• 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?

2.   Python uses indentation to specify compound statements. Give an example in support of this statement.

if x > y :
x = y
print “case 1”
All statements equally indented are included in the compound statement.

5.    What are the arguments pro and con, for Java’s approach to specify compound statements in control statements?

• Compound statements are required in control statements when the body of the if or else clause requires multiple statements.

• Java uses braces to form compound statements, which serve as the bodies of if and else clauses.

14.  State one of the main legitimate needs for gotos.

One of the main legitimate needs for gotos—premature exits from loops—can be met with highly restricted branch statements, such as break.