The way control of the CPU is transferred from one instruction to the next one.
Remember — The question is, “Who’s controlling the CPU?”
TODO Control flow graph explanation
TODO Example of control flow graph with code parallel.
Professor’s Opinion: A function written by a good programmer only has one exit point.
- If it has multiple exit points, it breaks modular reasoning.
Transfers control from one instruction to another unconditionally.Example: Unconditional Jump
...goto LABEL_ALABEL_A:...
Issues — The ability to jump anywhere leads to the spaghettication of code.
- “Goto considered harmful”
break: Jump out of loopreturn: Jump out of functioncontinue: Jump to next iterationlabeled break/continue: jump out/to of a nested loopFancy way of saying if-then-else.Example: General Syntax of Two-Way Selection
Statements
if B then S_1 else S_2 end
Design Issues:
You know what these are (TODO) On Default Case — Needed if you make non-exhaustive cases.Example: Multiple Selection Statements
select option in: case v_1 do s_1 ... case v_2 do s_2 ... case v_3 do s_3 ... default ...
Design Issues:
A way to introduce primitive recursion. Basically, any iteration that does a finite number of predetermined iterations.Example: General Syntax of Counter Controlled
Loops
for i \leftarrow init to n do S end
Design Issues:
Basically a pretty while loop. A more general version of the above. update(i) doesn’t even need to use i in C.Example: General Syntax of Generalized Loops
for i \leftarrow init until B(i) with update(i) do S end
while B do S end
There are some variants like do while.