1/47
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
control structure
A ___ is a control statement and the statements whose execution it controls
- Selection Statements
- Iterative Statements
Control Statements (2)
selection statement
A ___ provides the means of choosing between two or more paths of execution.
- Two-way selection
- Multiple-way selection
Selection statement fall into two general categories:
Form
The control expression is the condition you check to decide which block of code to execute
Type
The control expression must be of a boolean type, meaning it should evaluate to either true or false. In programming languages, this is enforced so that you can only use expressions that can logically be true or false.
parenthesis
Control expressions are specified in ___ if the then reserved word is not used to introduce the then clause, as in the C-based languages
C89
In ___, which did not have a Boolean data type, arithmetic expressions were used as control expressions
single statements
compound statements
In most contemporary languages, the then and else clauses either appear as ___ or ___.
braces
Perl
C-based languages use ___ to form compound statements.
One exception is ___, in which all then and else clauses must be compound statements, even if they contain single statements
Java and contemporary languages
In ___, the static semantics of the language specify that the else clause is always paired with the nearest unpaired then clause
curly braces {}
In Java, to force the else to associate with the outer if rather than the nearest inner if, you must use explicit block structure using ___.
statement nesting
C, C++, and C# have the same problem as Java with selection ___
indentation
Python, all statements uses ___ to define clauses
Multiple Selection Constructs
This allows the selection of one of any number of statements or statement groups.
differs from C-based
C# switch statement ___ in that C# has static semantic rule disallows the implicit execution of more than one segment
iterative statement
An ___ is one that cause a statement or collection of statements to be executed zero, one, or more times
iteration
recursion
The repeated execution of a statement or compound statement is accomplished either by ___ or ___
loop
An iterative statement is often called ___
logical
counting
The primary possibilities for iteration control are ___ or ___, or a combination of the two
location
The main choices for the ___ of the control mechanism are the top of the loop or the bottom of the loop
body
The ___ of a loop is the collection of statements whose execution is controlled by the iteration statement
pretest
The term ___ means that the loop completion occurs before the loop body is executed
posttest
The term ___ means that the loop completion occurs after the loop body is executed
iteration statement
The iteration statement and the associated loop body together form an ___
loop variable
A counting iterative control statement has a variable, called the ___, in which the count value is maintained
It also includes means of specifying the initial and terminal values of the loop variable, and the difference between sequential loop variable values, called the stepsize
more flexible
C's for is ___ than the counting loop statements of Fortran and Ada, because each of the expressions can comprise multiple statements, which in turn allow multiple loop variables that can be of any type
C99
C++
The for statement of___ and ___ differs from earlier version of C in two ways:
- It can use an arithmetic expression or a Boolean expression for loop control
- The first expression can include variable definitions (scope is from the definition to the end of the loop body), for example
for statement
The ___ of Java and C# is like that of C++, except that the loop control expression is restricted to Boolean
counter
Repetition control is based on a Boolean expression rather than a ___
C-based
The ___ programming languages include both pretest and posttest logically controlled loops that are not special forms of their counter-controlled iterative statements
least once
The only real difference between the do and the while is that the do always causes the loop body to be executed at ___
C and C++
Java's while and do statements are similar to those of ___, except the control expression must be Boolean type, and because Java does not have a goto, the loop bodies cannot be entered anywhere but at their beginning
User-Located Loop Control Mechanisms
It is sometimes convenient for a programmer to choose a location for loop control other than the top or bottom of the loop
unlabeled
labeled
C and C++ have unconditional ___ exits (break)
Java, Perl, and C# have unconditional ___ exits (break in Java and C#, last in Perl)
continue
C and C++ include an unlabeled control statement, ___, that transfers control to the control mechanism of the smallest enclosing loop
This is not an exit but rather a way to skip the rest of the loop statements on the current iteration without terminating the loop structure.
negative value
A ___ causes the assignment statement to be skipped, and control is transferred instead to the conditional at the top of the loop
labels
Java, Perl, and C# have statements similar to continue, except they can include ___ that specify which loop is to be continued
iterator
A general data-based iteration statement uses a user-defined data structure and a user-defined function to go through the structure's elements
The ___ is called at the beginning of each iteration, and each time it is called, it will return a n element from a particular data structure in some specific order
generic
C# and F# (and the other .NET languages) have ___ library classes, like Java 5.0 (for arrays, lists, stacks, and queues)
unconditional branch statement
An ___ transfers execution control to a specified place in the program
goto
The unconditional branch, or ___, is the most powerful statement for controlling the flow of execution of a program's statements
However, using it carelessly can lead to serious problems
Java
Python
Ruby
___, ___, and ___ do not have a goto. However, most currently popular languages include a goto statement
Dijkstra, 1975
Who suggested new and quite different forms of selection and loop structures?
His primary motivation was to provide control statements that would support a new program design methodology that ensured correctness (verification) during development rather than when verifying or testing completed programs _
Hoare, 1978
Who suggested the basis for two linguistic mechanisms for concurrent programming in CSP?
- Selection Statements
- Iterative Statements
- Unconditional Statements
Control statements occur in several categories: (3)
switch
The ___ statement of the C-based languages is representative of multiple-selection statements
Guarded commands
These are alternative control statement with positive theoretical characteristics