14 ControlFlow - Control Flow Scott, chapter 6 Basic...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Control Flow Scott, chapter 6
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Details in syntax and semantics differ between languages However, most fit into one of seven categories Sequencing statements are to be executed in a particular order, usually in the order appearing in the program text Basic paradigms for control flow
Background image of page 2
Selection a choice is made between two or more alternatives (statements or expressions) depending on a condition determined at runtime. if, case (switch) statements Iteration a given code fragment is executed repeatedly, either a given number of times or until a runtime condition is satisfied while, do, repeat loops
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
procedural abstraction a potentially complex collection of control constructs is encapsulated so that it can be treated as a single unit, often subject to parameterization recursion 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
Background image of page 4
nondeterminacy the ordering or choice among statements or expressions is deliberately left unspecified. Any alternative should lead to a correct result Sometimes fairness is required concurrency 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
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Relative importance of different categories varies among language paradigms sequencing central to imperative languages minor importance in functional languages, which emphasize expression evaluation recursion crucial in functional languages available in imperative languages iteration emphasized in imperative languages control flow (mostly) implicit in logic programming language
Background image of page 6
Expression evaluation Infix, prefix operators Precedence, associativity C has 15 levels - too many to remember Pascal has 3 levels - too few for good semantics Fortran has 8 Ada has 6 Ada puts at same level, usually & has higher precedence Lesson : when unsure, use parentheses!
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
An assignment statement takes two arguments a value (r-value) reference to a memory location where the value should be stored (l-value) Assignments are a building block of imperative languages a computation is an ordered sequence of changes to values in memory “computing by means of side effects” Assignments
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
a construct has a side effect if it influences the subsequence computation in any way other than returning a value functional languages focus on (usually side-effect- free) expression evaluation “pure functional languages do not have assignments” referential transparency —the value of an expression depends only on its referencing environment, not when it is evaluated. some functional languages do allow side effects for more
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 71

14 ControlFlow - Control Flow Scott, chapter 6 Basic...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online