8-Statement-Level%20Control%20Structure

8-Statement-Level%20Control%20Structure - 8....

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

View Full Document Right Arrow Icon
ICS 313 - Fundamentals of Programming Languages 1 8. Statement-Level Control Structure 8.1 Introduction ± Levels of Control Flow ` Within expressions ` Among program units ` Among program statements ± Evolution ` FORTRAN I control statements were based directly on IBM 704 hardware ` Much research and argument in the1960s about the issue ` One important result: It was proven that all flowcharts can be coded with only two-way selection and pretest logical loops ± A control structure is a control statement and the statements whose execution it controls ± Overall Design Question ` What control statements should a language have, beyond selection and pretest logical loops?
Background image of page 1

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

View Full DocumentRight Arrow Icon
ICS 313 - Fundamentals of Programming Languages 2 8.2 Compound statements ± Introduced by ALGOL 60 ± A block is a compound statement that can define a new scope (with local variables) 8.3 Selection Statements ± Design Issues ` What is the form and type of the control expression? ` What is the selectable segment form (single statement, statement sequence, compound statement)? ` How should the meaning of nested selectors be specified? ± Single-Way Examples ` FORTRAN IF: IF (boolean_expr) statement ` Problem: can select only a single statement; to select more, a GOTO must be used, as in the following example IF (.NOT. condition ) GOTO 20 ... ... 20 CONTINUE ` Negative logic is bad for readability ` This problem was solved in FORTRAN 77 ` Most later languages allow compounds for the selectable segment of their single-way selectors
Background image of page 2
ICS 313 - Fundamentals of Programming Languages 3 8.3 Selection Statements (continued) ± Two-way Selector Examples ± ALGOL 60 if : if ( boolean_expr ) then statement (the then clause) else statement (the else clause) ` The statements could be single or compound ± Nested Selectors ` e.g. (Java) if . .. if . .. ... else . .. ` Which if gets the else? ` Java's static semantics rule: else goes with the nearest if 8.3 Selection Statements (continued) ` ALGOL 60's solution - disallow direct nesting if . .. then if . .. then begin begin if . .. if . .. then . .. then . .. end else . .. else . .. end ` FORTRAN 90 and Ada solution - closing special words e.g. (Ada) if . .. then if . .. then if . .. then if . .. then ... ... else end if ... else end if ... end if end if ` Advantage: flexibility and readability
Background image of page 3

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

View Full DocumentRight Arrow Icon
ICS 313 - Fundamentals of Programming Languages 4 8.3 Selection Statements (continued) ± Multiple Selection Constructs ± Design Issues ` What is the form and type of the control expression? ` What segments are selectable (single, compound, sequences)? ` Is the entire construct encapsulated? ` Is execution flow through the structure restricted to include just a single selectable segment? ` What is done about unrepresented expression values?
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

8-Statement-Level%20Control%20Structure - 8....

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

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