Chapter 8 - Statement-Level Control Structures

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/47

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:16 PM on 5/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

48 Terms

1
New cards

control structure

A ___ is a control statement and the statements whose execution it controls

2
New cards

- Selection Statements

- Iterative Statements

Control Statements (2)

3
New cards

selection statement

A ___ provides the means of choosing between two or more paths of execution.

4
New cards

- Two-way selection

- Multiple-way selection

Selection statement fall into two general categories:

5
New cards

Form

The control expression is the condition you check to decide which block of code to execute

6
New cards

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.

7
New cards

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

8
New cards

C89

In ___, which did not have a Boolean data type, arithmetic expressions were used as control expressions

9
New cards

single statements

compound statements

In most contemporary languages, the then and else clauses either appear as ___ or ___.

10
New cards

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

11
New cards

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

12
New cards

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

13
New cards

statement nesting

C, C++, and C# have the same problem as Java with selection ___

14
New cards

indentation

Python, all statements uses ___ to define clauses

15
New cards

Multiple Selection Constructs

This allows the selection of one of any number of statements or statement groups.

16
New cards

differs from C-based

C# switch statement ___ in that C# has static semantic rule disallows the implicit execution of more than one segment

17
New cards

iterative statement

An ___ is one that cause a statement or collection of statements to be executed zero, one, or more times

18
New cards

iteration

recursion

The repeated execution of a statement or compound statement is accomplished either by ___ or ___

19
New cards

loop

An iterative statement is often called ___

20
New cards

logical

counting

The primary possibilities for iteration control are ___ or ___, or a combination of the two

21
New cards

location

The main choices for the ___ of the control mechanism are the top of the loop or the bottom of the loop

22
New cards

body

The ___ of a loop is the collection of statements whose execution is controlled by the iteration statement

23
New cards

pretest

The term ___ means that the loop completion occurs before the loop body is executed

24
New cards

posttest

The term ___ means that the loop completion occurs after the loop body is executed

25
New cards

iteration statement

The iteration statement and the associated loop body together form an ___

26
New cards

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

27
New cards

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

28
New cards

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

29
New cards

for statement

The ___ of Java and C# is like that of C++, except that the loop control expression is restricted to Boolean

30
New cards

counter

Repetition control is based on a Boolean expression rather than a ___

31
New cards

C-based

The ___ programming languages include both pretest and posttest logically controlled loops that are not special forms of their counter-controlled iterative statements

32
New cards

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 ___

33
New cards

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

34
New cards

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

35
New cards

unlabeled

labeled

C and C++ have unconditional ___ exits (break)

Java, Perl, and C# have unconditional ___ exits (break in Java and C#, last in Perl)

36
New cards

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.

37
New cards

negative value

A ___ causes the assignment statement to be skipped, and control is transferred instead to the conditional at the top of the loop

38
New cards

labels

Java, Perl, and C# have statements similar to continue, except they can include ___ that specify which loop is to be continued

39
New cards

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

40
New cards

generic

C# and F# (and the other .NET languages) have ___ library classes, like Java 5.0 (for arrays, lists, stacks, and queues)

41
New cards

unconditional branch statement

An ___ transfers execution control to a specified place in the program

42
New cards

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

43
New cards

Java

Python

Ruby

___, ___, and ___ do not have a goto. However, most currently popular languages include a goto statement

44
New cards

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 _

45
New cards

Hoare, 1978

Who suggested the basis for two linguistic mechanisms for concurrent programming in CSP?

46
New cards

- Selection Statements

- Iterative Statements

- Unconditional Statements

Control statements occur in several categories: (3)

47
New cards

switch

The ___ statement of the C-based languages is representative of multiple-selection statements

48
New cards

Guarded commands

These are alternative control statement with positive theoretical characteristics