08-control - 1 CSE 452 Programming Languages Control Flow 2 Organization of Programming Languages-Cheng Outline Control Structures Selection

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSE 452: Programming Languages Control Flow 2 Organization of Programming Languages-Cheng Outline Control Structures Selection Statements Iterative Statements Unconditional Branches Subprograms and Procedures 2 3 Organization of Programming Languages-Cheng Iterative Statements Repeated execution of a statement or compound statement accomplished either by iteration or recursion; here we look at iteration, because recursion is a unit- level control (e.g., using functions) General design issues for iteration control statements: How is the iteration controlled? Counter-controlled vs logical-controlled Where should the control mechanism appear in the loop? pretest (before loop body is executed) vs posttest (after loop body is executed) 4 Organization of Programming Languages-Cheng Iterative Statements Counter-Controlled Loops for (i = init_value; i < terminal_value; i+=stepsize) { … } Design Issues: What are the type and scope of the loop variable? What is the value of the loop variable at loop termination? Should it be legal for the loop variable or loop parameters to be changed in the loop body, and if so, does the change affect loop control? Should the loop parameters be evaluated only once, or once for every iteration? Loop parameters Loop variable 3 5 Organization of Programming Languages-Cheng Counter-Controlled Loops FORTRAN 95 Syntax: D o label var = initial, terminal [, stepsize] stepsize can be any value but zero parameters can be expressions Design choices: 1. Loop var must be integer; loop parameters can be expressions 2. The loop var cannot be changed in the loop, but loop parameters can because they are evaluated only once, it does not affect loop control 3. Single entry structure – loop can be entered through Do statement 6 Organization of Programming Languages-Cheng Counter-Controlled Loops Fortran 95: Do label var = init_expression, terminal_expression [, step_expression] Operational Semantics for Fortran 95 Do statement init_value = init_expression terminal_value = terminal_expression step_value = step_expression do_var = init_value iteration_count = max(int((terminal_value–init_value+step_value)/step_value), 0) loop: if iteration_count ≤ 0 goto out [loop body] do_var = do_var + step_value iteration_count = interation_count – 1 goto loop out: … 3 5 Organization of Programming Languages-Cheng Counter-Controlled Loops FORTRAN 95 Syntax: D o label var = initial, terminal [, stepsize] stepsize can be any value but zero parameters can be expressions Design choices: 1. Loop var must be integer; loop parameters can be expressions 2. The loop var cannot be changed in the loop, but loop parameters can because they are evaluated only once, it does not affect loop control 3. Single entry structure – loop can be entered through Do statement 6 Organization of Programming Languages-Cheng Counter-Controlled Loops...
View Full Document

This note was uploaded on 07/25/2008 for the course CSE 452 taught by Professor Cheng during the Fall '05 term at Michigan State University.

Page1 / 21

08-control - 1 CSE 452 Programming Languages Control Flow 2 Organization of Programming Languages-Cheng Outline Control Structures Selection

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

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