/ Faculteit Wiskunde en Informatica
PAGE 0 20-11-2008
Ch 9: Control flow
- We will study a number of alternatives
- traditional sequencers:
− sequential − conditional − iterative
- jumps, low-level sequencers to transfer control
- escapes, sequencers to transfer control out of
commands and procedures
- exceptions, sequencers to signal abnormal situations
/ Faculteit Wiskunde en Informatica
PAGE 1 20-11-2008
Sequencers
- A sequencer is a language construct to transfer
control to some other point in a program, destination
- A sequencer implements a flow of control
/ Faculteit Wiskunde en Informatica
PAGE 2 20-11-2008
Jumps
- A jump transfers control to a specified program point
- A jump has typical the form goto L; and transfer the control to
program point L, which is a label if (E1) C1 else { C2 goto X; } C3; while (E2) { C4; X: C5 }
/ Faculteit Wiskunde en Informatica
PAGE 3 20-11-2008
Jumps
- Unrestricted jumps lead to spaghetti code, thus hard to understand,
see http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
- Most programming languages support gotos
- Java refuses jumps, because it supports higher-level escapes and
exceptions
- Some languages have restrictions:
- the jump goto L; is legal only within the scope of L