Control Flow Flashcards

1
Q

Basic Paradigms for Control Flow

(T/F)

Details in syntax and semantics do not differ between languages.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Seven Categories for Control Flow

A
  • Sequencing
  • Selection
  • Iteration
  • Procedural Abstraction
  • Recursion
  • Non-Determinacy
  • Concurrency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe Sequencing.

A

Statements are to be executed in a particular order, usually in the order appearing in the program text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define Selection.

A
  • A choice is made between two or more alternatives (statements or expressions) depending on a condition determined at runtime.
  • If, case (switch) statements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Iteration.

A
  • A given code fragment is executed repeatedly, either a given number of times or until a runtime condition is satisfied.
  • While, do, repeat loops.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe Procedural Abstraction.

A

A potentially complex collection of control constructs is encapsulated so that it can be treated as a single unit, often subject to parameterization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe Recursion.

A
  • An expression is defined in terms of simpler versions of itself.
  • The computational model requires a stack on which to save information about partially evaluated instances of the expression.
  • Usually defined using self-referential subroutines.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe Non-Determinacy.

A
  • The ordering or choice among statements or expressions is deliberately left unspecified.
  • Any alternative should lead to a correct result.
  • Sometimes “fairness” is required.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define Concurrency.

A
  • Two or more program fragments are to be executed “at the same time”, either in parallel on separate processors or interleaved in a single processor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Sequencing

Imperative VS Functional Languages

A
  • Central to imperative languages.
  • Minor importance in functional languages, which emphasize expression evaluation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Recursion

Imperative VS Functional Languages

A
  • Crucial in functional languages
  • Available in imperative languages
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Iteration

Imperative VS Functional Languages

A
  • Emphasized in imperative languages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Precedence Associativity

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Assignments

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Construct Side Effects

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Value Model of Variables

A
17
Q

Reference Model

A
18
Q

Boxing in Java

A
19
Q

Multiway Assignment

A
20
Q

What are some advantages to Initialization?

A
  • Initial value of statically allocated variables can be set by compiler.
  • Helps avoid common programming error of using variable before it has a value (or at least making behavior repeatable).
21
Q

Ordering Within Expressions

(a + b) * (c + d)
f (a+b, c+d)

Which will be evaluated first? (a + b) or (c + d)
Not determined by precedence or associativity rules

A
22
Q

Order Within Expressions

A
23
Q

C, C++ define “sequence points” that constrain order of evaluation. What happens between sequence points?

A
24
Q

Evaluation Between Sequence Points in C:

Assume x has value 1 before the expression

x[i] = i++ + 1;

What happens?

A

Undefined—both outcomes below are allowed

x[i] = i++ + 1;

x[1] = 2, i==2
x[2] = 2, i==2

Instead use

x[i] = i+1;
i++;

25
Q

Evaluation Between Sequence Points in C:

f( i++, j++, i+j)

What value is passed to f in the 3rd parameter?

A

f( i++, j++, i+j)

Could be 3,4,5

Instead use

i++;
j++;
f(i,j,i+j)

26
Q

Structured VS Unstructured

A

Unstructured Control Flow

  • Use goto statement
  • Fortran example
    • if condition goto 10

Structured

  • Use only sequencing, selection, and iteration.
  • Use boundaries of lexically nested constructs as targets of branches instead of labels.
27
Q

(T/F)

Goto statement are not considered harmful.

A

False

28
Q

Case/Switch Statement

Rather than testing each case sequentially, the case statement may compute the address of the jump target.

What are some of the implementation techniques?

A
29
Q

Iteration

Describe the following:

  • Enumeration Controlled Loop
  • Logically Controlled Loop
A
30
Q

Logically Controlled Loops

A
31
Q

Enumeration Controlled Loop

A
32
Q

Parallel Loops

A
33
Q

Recursion VS Iteration

Which is more efficient?

A
  • A naive implementation of iteration usually more efficient than naive implementation of recursion since recursion makes actual subroutine calls.
  • However, high quality compilers (especially those for a functional language) can generate efficient recursive code.