PROP 8. Statement-Level Control Structures

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

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

# What are the design issues for all iterative control statements?

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

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

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

# What is a user-defined iteration control?

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. The for loop fo C based languages can simulate a user defined iteration statement because of it great flexibility. for (ptr=root; ptr==null; ptr=traverse(ptr)) { } Assuming that traverse is a runction that will set ptr to the next desired elment of a data structure, this for loop will begin with root and will continue going through the elements until ptr points to a null element. Many languages provide predefined iterators which are based on the data structure that they are meant to travers, such as Pearl. reset $list -> moves the iterator to the 1st element current($list) -> retrieves the current element of list next($list) -> moves the iterator to the next element in the data structure.

# On what previous language was C's switch statement based?

ALGOL 68

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

All 3 expressions are optional. Each expression can be entire statement or sequence. Expression value is value of last statement. Everything can be changed within the loop. Legal to branch into the body of a loop.

# What is the definition of block?

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

# 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. Every segment must end with an explicit unconditional branch statement which transfer control out of the switch statement, or a goto, which can transfer control to one of the selectable segments

# What are the differences between the break statement of C++ and that of Java?

C++'s break is unconditional unlabeled exits, meanwhile Java's one is unconditional labeled exits.

# What is the definition of control structure?

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

# What common programming language borrows part of its design from Dijkstra's guarded commands?

Dijkstra's guarded commands are the basis of concurrence mechanism in CSP and Ada, also function definitions of Haskell.

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

If the expression returns a value, it must have an else clause

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

In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++, unrepresented values can be caught at run time with the default selector. If there is no default, an unrepresented value causes the whole statement to be skipped.

# What does the range function in Python do?

It is used to count loops in Python

# What contemporary languages do not include a goto?

Java language is the contemporary language that doesn't include a goto, the loop bodies cannot be entered anywhere but at their beginning.

# What advantage does Java's break statement have over C's break statement?

Java's break is unconditional labeled exits, so we can create a label to a loop anywhere, and we can cancel that loop with break <loopname> statement. Meanwhile, in C++, break is unconditional unlabeled exits, so breaks in here treated as a statement, that will exit nearest loop (Java can do this too).

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

Pretest means that the test for loop completion occurs before the loop body is executed and posttest means thar it occurs after the loo body is executed.

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

# How are iterators implemented in Ruby?

Ruby predefines several iterator methods, such as times and upto for counter-controlled loops, and each for simple iterations of arrays and hashes.

# What language predefines iterators that can be explicitly called to iterate over its predefined data structures?

Ruby: TIMES, EACH, UPTO Or: php: CURRENT, NEXT, PREV

# What is the design issues for all selection and iteration control statement?

Selection : Two-way : -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 ? Multiple-Selection : -On which type the selector is based ? Iteration : -How is the iteration controlled ? -Where should the control mechanism appear in loop statement?

# What did Bohm and Jocopini prove about flowcharts?

The Bohm-Jacopini proof describes how to construct a structured flow chart from an arbitrary chart, using the bits in an extra integer variable to keep track of information that the original program represents by the program location. This construction was based on Bohm's programming language P′′. The Bohm-Jacopini proof did not settle the question of whether to adopt structured programming for software development, partly because the construction was more likely to obscure a program than to improve it. On the contrary, it signalled the beginning of the debate. Edsger Dijkstra's famous letter, "Go To Statement Considered Harmful," followed in 1968. Subsequent proofs of the theorem addressed practical shortcomings of the Bohm-Jacopini proof with constructions that maintained or improved the clarity of the original program.

# What is unusual about C's multiple-selection statement?

The C switch statement has virtually no restrictions on the placement of the case expressions, which are treated as if they were normal statement labels. This laxness can result in highly complex structure eithin the switch body.

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

The common solution to the nesting problem is to use alternating means of forming a compound statements.

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

The design issues for user located loop controlled mechanism 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 is the difference between the for statement of C++ and that of Java?

The loop control expression in Java is restricted to boolean, unlike that of C++, even though the syntax is similar.

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

The main reason user-located loop control statement were invented is to choose a location for loop control other than the top or bottom of the loop body.


Conjuntos de estudio relacionados

ITSP 136 A+ CompTIA A+ Core 1 (220-1101) and Core 2 (220-1102) Exam Cram Chapters 13-16

View Set

Class 11: Insider Trading - Part 1 Classical Theory & Misappropriation Theory

View Set

MGMT Of Human Resources Chapter 10: Building Positive Employee Relations

View Set

Water Features of the United States

View Set

Chapter 40: Corporate Directors, Officers, and Shareholders

View Set

CH 4 Epidemiologic Measures of Population Health

View Set