Chapter 6 Control Flow

Expression evaluation

Exception to expression

{in,pre,post}fix

Expressions and typical languages

Precedence and associativity

Assignment

References and Values

(f(a)+3)->b[c] = 2;

Orthogonality and Algol 68

Algol 68: it is just an expression

begin
   a := if b < c then d else e;
   a := begin f(b); g(c) end;
   g(d);
   2 + 3;
end

C: close to the same

Combination assignment operators

Multiway assignment

a,b = b,a
a,b,c = func(d,e,f)

Initialization

Uninitialization

Constructors

Ordering within expressions

Application of Mathematical Identities

a = b + c
d = c + e + b
a = b + c
d = a + e

Short-circuit evaluation

if(x or y)

Short-circuit evaluation

if(x and y)

C

if(p && p->value != something)
{
   p = p->next;
}

Pascal doesn't short-circuit

Short-circuits and side-effects

6.2 Structured and Unstructured Flow

jmp X    =>  PC := X
branch X =>  PC := PC + X
call X   =>  PUSH PC, PC := X

GOTO

Perl's structured alternatives: next, last, redo

C's continue

Multi-level returns

Errors and other exceptions

Continuations

6.3 Sequencing

6.4 Selection

6.4.1 Short-circuits

if ((A>B) and (C>D) or (E != F) then
  then-clause
else
  else-clause

6.4.1 Short-circuits

  r1 := A
  r2 := B
  if r1 <= r2 goto L4
  r1 := C
  r2 := D
  if r1 > r2 goto L1

(continued)

L4:
  r1:=E
  r2:=F
  if r1 == r2 goto L2
L1:
  then-clause
  goto L3
L2:
  else-clause
L3:

6.4.1 Short-circuits

6.4.2 Case/Switch statements

6.4.2

case (X) 
  1: do_something();
  200000: do_something_else();
  20000000000: do_other_stuff();
endcase

6.4.2

6.5 Iteration

6.5.1 Enumeration-controlled loops

6.5.2 Combination loops

for(INITIALIZATION;
    BOOLEANEXPRESSION;
    ITERATIONSTEP) 

6.5.5 Logically controlled loops

6.6.1 Iteration and recursion

6.6.1 Iteration and recursion

6.6.2 Applicative- and normal-order evaluation

Chapter Summary