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/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:24 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

33 Terms

1
New cards

Control Structure

a control statement and the statements whose execution it controls

2
New cards

2 types of control structures

Selection Statements -- Iterative Statements

3
New cards

Only design issue relevant to all selection and iteration control statements

Should a control structure have multiple entries?

4
New cards

Selection Statement

provides the means of choosing between two or more paths of execution

5
New cards

2 categories of selection statements

Two-way selection -- Multiple-way selection

6
New cards

3 design issues for two-way selection

form and type of the control expression -- how then and else clauses are specified -- how meaning of nested selectors is specified

7
New cards

Control Expression in C89

used arithmetic expressions -- nonzero is true -- zero is false

8
New cards

Control Expression in Java/C#

only Boolean expressions allowed

9
New cards

Clause Form in C-based languages

uses braces to form compound statements

10
New cards

Clause Form in Perl

all then and else clauses must be compound statements even if they contain a single statement

11
New cards

Clause Form in Python

uses indentation to define clauses -- colon used instead of then

12
New cards

Nesting Selectors rule

else clause is always paired with the nearest unpaired then clause -- applies in Java and contemporary languages

13
New cards

C# switch

differs from C-based switch -- static semantic rule disallows implicit execution of more than one segment -- every segment must end with break or goto

14
New cards

Iterative Statement

causes a statement or collection of statements to be executed zero, one, or more times -- often called a loop

15
New cards

Pretest loop

loop completion condition checked before the loop body is executed -- example: while

16
New cards

Posttest loop

loop completion condition checked after the loop body is executed -- example: do-while

17
New cards

Key difference: while vs do-while

do-while always executes the loop body at least once

18
New cards

Counter-Controlled Loop

has a loop variable -- specifies initial value, terminal value, and stepsize

19
New cards

Stepsize

the difference between sequential loop variable values

20
New cards

Loop Parameters

the initial, terminal, and stepsize values

21
New cards

C for loop infinite loop

if the second expression is absent

22
New cards

C for vs Fortran/Ada

C's for is more flexible -- each expression can comprise multiple statements -- allows multiple loop variables of any type

23
New cards

Java/C# for loop

like C++ except loop control expression is restricted to Boolean

24
New cards

Logically Controlled Loop

repetition based on a Boolean expression rather than a counter

25
New cards

User-Located Loop Exits -- C/C++

unconditional unlabeled exits using break

26
New cards

User-Located Loop Exits -- Java/C#/Perl

unconditional labeled exits (break in Java/C# -- last in Perl)

27
New cards

continue statement

skips the rest of the current iteration without terminating the loop -- transfers control to the loop's control mechanism

28
New cards

Iterator

called at the beginning of each iteration -- returns an element from a data structure in a specific order

29
New cards

foreach in C#

iterates on elements of arrays and other collections -- uses built-in iterators of predefined generic collections

30
New cards

Unconditional Branch / goto

the most powerful statement for controlling execution flow -- carelessly used, it makes programs difficult to read and unreliable

31
New cards

Languages without goto

Java -- Python -- Ruby

32
New cards

Guarded Commands (Dijkstra 1975)

alternative control statements -- evaluates all Boolean guards -- if more than one true, chooses non-deterministically -- if none true, runtime error -- basis for CSP concurrency mechanisms

33
New cards

Motivation for Guarded Commands

support program correctness verification during development rather than after completion