livingmylivetothefullest

It's about life

Chapter 8

Statement-Level Control Structures

Assignment from Tri Djoko Wahjono

Review Questions

1. What is the definition of control structure?
Control structure is a control statement and the collection of statements whose execution it controls.

2. What did Bohm and Jocopini prove about flowcharts?
It was proven that all algorithms that can be expressed by flowcharts can be coded in a programming languages with only two control statements: one for choosing between two control flow paths and one for logically controlled iterations.

3. What is the definition of block?
Block is a sequence of code delimited by either braces or the do and end reserved words.

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.

5. What are the design issues for selection structures?
– 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?

6. What is unusual about Python’s design of compound statements?
Python uses indentation to specify compound statements. For example,
if x > y :
x = y
print “case 1″
equally indent statements are grouped as one compound statement.

7. Under what circumstances must an F# selector have an else clause?
An F# selector have an “else” clause if 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?
– How are the case values specified?
– How should unrepresented selector expression values be handled, if at all?
– Is execution flow through the structure restricted to include just a single selectable segment?

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?

21. What are the design issues for logically controlled loop statements?
– Should the control be pretest or post-test?
– Should the logically controlled loop be a special form of a counting loop or a separate statement?

23. What are the design issues for user-located loop control mechanisms?
– 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?

Problem Set

1. Describe three situations where a combined counting and logical looping statement is needed.
Three situations in which a combined counting and logical control loops are:
a. A list of values is to be added to a SUM, but the loop is to be exited if SUM exceeds some prescribed value.
b. A list of values is to be read into an array, where the reading is to terminate when either a prescribed number of values have been read or some special value is found in the list.
c. The values stored in a linked list are to be moved to an array, where values are to be moved until the end of the linked list is found or the array is filled, whichever comes first.

4. What are the pros and cons of using unique closing reserved words on compound statements?
Unique closing keywords on compound statements have the advantage of readability and the disadvantage of complicating the language by increasing the number of keywords.

9. What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also allowing arithmetic expressions, as in C++)?
The primary argument for using Boolean expressions exclusively as control expressions is the reliability that results from disallowing a wide range of types for this use. In C, for example, an expression of any type can appear as a control expression, so typing errors that result in references to variables of incorrect types are not detected by the compiler as errors.No , it would not be a good idea. Although this custom precedence sounds like increasing flexibility, requiring parentheses to show a custom precedence would impact in readability and writability of a program.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on June 28, 2013 by .
June 2013
M T W T F S S
« Apr   Sep »
 12
3456789
10111213141516
17181920212223
24252627282930

Blog Stats

  • 6,909 hits
%d bloggers like this: