You are on page 1of 3

Chapter 8

1. What is the definition of control structure? -How should the meaning of nested selectors be
Control structure is a control statement and the specified ?
collection of statements whose execution it Multiple-Selection :
controls. -On which type the selector is based ?
2. What did Böhm and Jocopini prove about
flowcharts? Iteration :
he Bohm-Jacopini proof describes how to -How is the iteration controlled ?
construct a structured flow chart from an -Where should the control mechanism appear
arbitrary chart, using the bits in an extra integer in loop statement?
variable to keep track of information that the 5. What are the design issues for selection
original program represents by the program structures?
location. This construction was based on -What is the form and type of the expression
Bohm’s programming language P′′. The Bohm- that controls the selection ?
Jacopini proof did not settle the question of
whether to adopt structured programming for -How are the then and else clauses specified ?
software development, partly because the
construction was more likely to obscure a -How should the meaning of nested selectors be
program than to improve it. On the contrary, it specified ?
signalled the beginning of the debate. Edsger 6. What is unusual about Python’s design of
Dijkstra’s famous letter, “Go To Statement compound statements?
Considered Harmful,” followed in 1968. Python uses indentation to specify compound
Subsequent proofs of the theorem addressed statements. For example,
practical shortcomings of the Bohm-Jacopini if x > y :
proof with constructions that maintained or x=y
improved the clarity of the original program. print "case 1"
3. What is the definition of block? equally indent statements are grouped as one
A block is a section of code which is grouped compound statement.
together. Blocks consist of one or more 7. Under what circumstances must an F#
declarations and statements. A programming selector have an else clause?
language that permits the creation of blocks, If the expression returns a value, it must have
including blocks nested within other blocks, is an else clause
called a block-structured programming 8. What are the common solutions to the
language. nesting problem for two-way
4. What is/are the design issue(s) for all selectors?
selection and iteration control The common solution to the nesting problem is
statements? to use alternating means of forming a
Selection : compound statements.
Two-way : 9. What are the design issues for multiple-
-What is the form and type of the expression selection statements?
that controls the selection ? What is the form and type of the expression
-How are the then and else clauses specified ? that controls the selection?
- How are the selectable segments specified?
- Is execution flow through the structure 15. What are the design issues for counter-
restricted to include just a single selectable controlled loop statements?
segment? -What are the type and scope of the loop
- How are the case values specified? variable ?
- How should unrepresented selector
expression values be handled, if at all? -Should it be legal for the loop variable or loop
10. Between what two language characteristics parameters to be changed in the loop, and if so,
is a trade-off made when deciding whether does the change affect loop control ?
more than one selectable segment is executed
in one execution of a multiple selection -Should the loop parameters be evaluated only
statement? once, or once for every iteration ?
In Ada, the choice lists of the case statement 16. What is a pretest loop statement? What is
must be exhaustive, so that there can be no a posttest loop statement?
unrepresented values in the control expression. Pretest means that the test for loop completion
In C++, unrepresented values can be caught at occurs before the loop body is executed and
run time with the default selector. If there is no posttest means that it occurs after the loo body
default, an unrepresented value causes the is executed.
whole statement to be skipped. 17. What is the difference between the for
11. What is unusual about C’s multiple- statement of C++ and that of Java?
selection statement? The loop control expression in Java is restricted
The C switch statement has virtually no to boolean, unlike that of C++, even though the
restrictions on the placement of the case syntax is similar.
expressions, which are treated as if they were 18. In what way is C’s for statement more
normal statement labels. flexible than that of many other languages?
All 3 expressions are optional.
This laxness can result in highly complex Each expression can be entire statement or
structure within the switch body. sequence.
12. On what previous language was C’s switch
statement based? Expression value is value of last statement.
ALGOL68 Everything can be changed within the loop.
13. Explain how C#’s switch statement is safer Legal to branch into the body of a loop.
than that of C. 19. What does the range function in Python
C# has a static semantics rule that disallows the do?
implicit execution of more than one segment. It is used to count loops in Python
Every segment must end with an explicit 20. What contemporary languages do not
unconditional branch statement which transfer include a goto?
control out of the switch statement, or a goto, Java language is the contemporary language
which can transfer control to one of the that doesn't include a goto, the loop bodies
selectable segments cannot be entered anywhere but at their
14. What are the design issues for all iterative beginning.
control statements? 21. What are the design issues for logically
-How is the iteration controlled ? controlled loop statements?
-Where should the control mechanism appear - Should the control be pretest or posttest?
in loop statement?
- Should the logically controlled loop be a 27. What Scheme function implements a
special form of a counting loop or a separate multiple selection statement?
statement? The Scheme multiple selector, which is based
22. What is the main reason user-located loop on mathematical conditional expressions, is a
control statements were special form function named COND. COND is a
invented? slightly generalized version of the mathematical
The main reason user-located loop control conditional expression; it allows more than one
statement were invented is to choose a location predicate to be true at the same time. Because
for loop control other than the top or bottom of different mathematical conditional expressions
the loop body. have different numbers of parameters, COND
23. What are the design issues for user-located does not require a fixed number of actual
loop control mechanisms? parameters. Each parameter to COND is a pair
The design issues are whether the conditional of expressions in which the first is a predicate (it
mechanism should be an integral part of the evaluates to either #T or #F).
exit or not & whether only loop body should be 28. How does a functional language implement
exited or enclosing loops can also be exited. repetition?
24. What advantage does Java’s break Recursion
statement have over C’s break 29. How are iterators implemented in Ruby?
statement? Ruby predefines several iterator methods, such
- Java's break is unconditional labeled exits, so as times and upto for counter-controlled loops,
we can create a label to a loop anywhere, and and each for simple iterations of arrays and
we can cancel that loop with break <loopname> hashes.
statement. Meanwhile, in C++, break is 30. What language predefines iterators that
unconditional unlabeled exits, so breaks in here can be explicitly called to iterate over its
treated as a statement, that will exit nearest predefined data structures?
loop (Java can do this too). Ruby: TIMES, EACH, UPTO
25. What are the differences between the Or: php: CURRENT, NEXT, PREV
break statement of C++ and that 31. What common programming language
of Java? borrows part of its design from Dijkstra’s
C++'s break is unconditional unlabeled exits, guarded commands?
meanwhile Java's one is unconditional labeled Dijkstra's guarded commands are the basis of
exits. concurrence mechanism in CSP and Ada, also
26. What is a user-defined iteration control? function definitions of Haskell.
A user defined iteration control is a type of
looping structure that is primarily used for data
structures. Instead of being controlled by a
counter or boolean expression, it is controlled
by the number of elements in a data structure.
In order to achieve this the user-defined control
uses a user-defined frunction called an iterator.
This iterator is used to traverse through the
data structure and retrieve the elements in
whatever order the programmer defines.

You might also like