07-02-2012, 03:37 PM
Statement-Level Control Structures
[attachment=17254]
Control Statements: Evolution
•FORTRAN I control statements were based
directly on IBM 704 hardware
•Much research and argument in the 1960s
about the issue
–One important result: It was proven that all
algorithms represented by flowcharts can be
coded with only two-way selection and logically
controlled iterations
The Control Expression
•If the then reserved word is not used
–control expressions are specified in parentheses
•If the then reserved word is used
–Less need for parentheses
•In C89, arithmetic expressions were used
as control expressions
•In Ada, Java, Ruby, and C#, only Boolean
expressions can be used
Multiple-Way Selection Statements
• Allow the selection of one of any number
of statements or statement groups
• Design Issues:
1. What is the form and type of the control expression?
2. How are the selectable segments specified?
3. Is execution flow through the structure restricted
to include just a single selectable segment?
4. How are the case values specified?
5. What is done about unrepresented expression
values?
Design Choices for C’s switch
1. Control expression and constant expressions
are some integer type
2. Selectable segments can be statement
sequences, blocks, or compound statements
3. Any number of segments can be executed in
one execution of the construct (there is no
implicit branch at the end of selectable
segments)
4. default clause is for unrepresented values (if
there is no default, the whole statement does
nothing)