Types of Structured Sequential Control Types of Unstructured Control  GOTO  coroutines Asynchronous Control (stay tuned) Concurrent Control (stay tuned)

Slides:



Advertisements
Similar presentations
Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
Advertisements

ICE1341 Programming Languages Spring 2005 Lecture #13 Lecture #13 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Statement-Level Control Structures
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha Control Flow-II: Execution Order.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements Iterative.
(8.1) COEN Control Structures  Control structure general issues  Compound statements  Selectors (conditional structures) – single – two-way –
ISBN Chapter 8 Statement-Level Control Structures.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Chapter 8 Statement-Level Control Structure. Introduction Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements.
ISBN Chapter 8 Statement-Level Control Structures.
PZ07B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07B - Basic statements Programming Language Design.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
ISBN Chapter 8 Statement-Level Control Structures.
ISBN Chapter 8 Statement-Level Control Structures.
Chapter 8 (Control Structure) Slide 1 Control Structures Control structures are used by the programmer to incorporate the desired sequence of execution.
Control Structures. Hierarchical Statement Structure Standard in imperative languages since Algol60. Exceptions: Early FORTRAN, COBOL, early BASIC, APL.
Program Design and Development
Statement-Level Control Structures Sections 1-4
ISBN Chapter 8 Statement-Level Control Structures.
ISBN Lecture 08 Statement-Level Control Structures.
UNIT II Decision Making And Branching Decision Making And Looping
COMP4730/2002/lec8/H.Melikian Statement-Level Control Structures Introduction Compound Statements Selection Statements Iterative Statements Unconditional.
1 Statement-Level Control Structures Levels of flow control Control Statements 1. Sequence 2. Selection 3. Iteration Unconditional branching Guarded commands.
ISBN Chapter 8 Statement-Level Control Structures Sections 1-4.
CPS120: Introduction to Computer Science Decision Making in Programs.
PLLab, NTHU,Cs2403 Programming Languages Expression and control structure Kun-Yuan Hsieh Programming Language Lab., NTHU.
Principle of Programming Lanugages 2: Imperative languages Isao Sasano Department of Information Science and Engineering ( structured programming, control.
Control Structures Programs have 4 basic control structures:
Chapter 8 Chapter 8 Control Structures. Control Structures  A control structure is a control statement and the statements whose execution it controls.
ISBN Chapter 8 Statement-Level Control Structures.
1 CS Programming Languages Class 11 September 26, 2000.
sequence of execution of high-level statements
Expressions and Statements. Expressions Literals and identifiers are expressions More complex expressions are built from simple expressions by the application.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
第八章 敘述層級的控制結構 (Statement-Level Control Structures)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Control Structures sequence of execution of high-level statements.
8-1 Statement-Level Control Structures Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions.
C HAPTER 8 Statement-Level Control Structures. CCSB314 Programming Language C HAPTER 8 T OPICS Introduction Selection Statements Iterative Statements.
April 16, ICE 1341 – Programming Languages (Lecture #14) In-Young Ko Programming Languages (ICE 1341) Lecture #14 Programming Languages (ICE 1341)
Statement Level Flow of Control Iteration Structures Copyright © by Curt Hill.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 7 Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements.
1 Iterative Statements Repeated execution of a (compound) statement by iteration or recursion –Iteration is statement level –Recursion is unit-level control.
Statement Level Flow of Control GOTOs and Other Weirdness Copyright © by Curt Hill.
Chapter 8 © 2002 by Addison Wesley Longman, Inc Introduction - Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program.
W E E K F I V E Statement-Level Control Structures.
LECTURE 18 Control Flow. CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear.
W E E K F I V E Control Flow. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements Iterative Statements.
CS 36 – February 2 Control structures –Sequence √ –Loops √ –Selection If-statement Case-statement Finding loops.
Chapter 8 Statement-Level Control Structures. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements.
Programming Techniques
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Def: A control structure is a control statement and
8.1 Introduction - Levels of Control Flow: 1. Within expressions
Dr. Vamsi Paruchuri University of Central Arkansas
Statement-Level Control Structures
Chapter 8: Control Structures
Statement-Level Control Structures
Control Structures In Text: Chapter 8.
Control Structures Programs utilize 4 basic control structures
Statement-Level Control Structures
Chapter8: Statement-Level Control Structures April 9, 2019
Chapter 8: Statement Level Control Structures
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Types of Structured Sequential Control Types of Unstructured Control  GOTO  coroutines Asynchronous Control (stay tuned) Concurrent Control (stay tuned)

Simple Sequence - execute instructions in the written order  What instructions are inherently sequential?  Why {...} notation (or begin... end)? Selection - choose between alternative code clauses  What are the two forms in Java/C++ ?  Distinguishing characteristics between selection control structures:  Examples:  if -- Java  CASE -- Modula-2  COND -- Scheme  arithmetic- IF -- FORTRAN IF ( expression ) 100, 200, 300

Java/C/C++ Pascal/Algol 60 if ( condition ) thenClause ; else elseClause ; if condition then thenClause else elseClause Modula-2/Ada if condition thenClause ; else elseClause ; end if

1st Generation  IF ≈ optional branch (2-way selection)  examples: conditional branches -- assembler logical IF -- FORTRAN IF -- BASIC 2nd Generation  if-then-else replaces if-then  examples: Pascal & C  concern: branching into the midst of a clause  concern: dangling else

When does the else clause execute? if ( condition1 ) if ( condition2 ) thenClause ; else elseClause ; How to write the code as indented?

1st Generation  IF either branches or not (2-way selection)  examples: conditional branches -- assembler logical IF -- FORTRAN IF -- BASIC 2nd Generation  if-then-else replaces if-then  examples: Pascal & C  concern: branching into the midst of a clause  concern: dangling else 3rd Generation  elseif option is included  examples: Algol 68, Ada & Modula-2

Computed-GOTO -- FORTRAN GOTO (10, 20, 30, 40), integerExpression 10 Instruction1... GOTO Instruction2... GOTO Instruction3... GOTO Instruction4... GOTO CONTINUE

Select -- PL/1 SELECT ( Expression ); WHEN(0, 1) Instruction1 ; WHEN(7) Instruction2 ;... OTHERWISE InstructionN ; END; OR SELECT; WHEN( Condition1 ) Instruction1 ; WHEN( Condition2 ) Instruction2 ;... OTHERWISE InstructionN ; END;

switch -- C switch ( Expression ) { case constant1 : Instruction1 ; break; case constant2 : case constant3 : Instruction1 ; break;... default: InstructionN ; break; }

Guarded-IF (by Edsgar Dijkstra) if condition1  clause1  condition2  clause2  condition3  clause3...  conditionN  clauseN fi Non-deterministic code has alternative valid behavior under the same circumstances. Ada Select select when condition1 => clause1 or when condition2 => clause2 or when condition3 => clause3... or when conditionN => clauseN end select

Repetition Control Structures - execute a body repeatedly    EXIT -- Modula-2 & Ada  break -- C et. al.  LEAVE -- PL/1 (What occurs when a continue instruction (C) executed?) DO J=1 TO 10 BY 2, 17, 23 WHILE (X>0);... IF (Y=1) THEN LEAVE;... END;  control structures run amuck - PL/1  top of loop ( while )  bottom of loop ( repeat/do )

The Counting Loop -- What hath FORTRAN wrought? Early versions of FORTRAN had one loop construct. DO 1000 j=1,20, CONTINUE Modern versions of this loop are called for loops. Modula-2 restrictions. Ada version: for ControlVar in loop... end loop Under what circumstances do these Modula-2 loops behave differently? FOR J:=1 TO A[N] DO loopBody ; END; J:=1; WHILE J<=A[N] DO loopBody ; J:=J+1; END;

Zahn’s Event Indicator  loop until repeat then fi  | or  |  : ; BNF loop until E 1 or... or E N loopBody repeat then E 1 : Instruction1 ;... E N : InstructionN ; fi Skeleton

Example: sequential array search j := 1; loop until Found or NotThere begin if j>arraySize then NotThere; if A[j]=lookupValue then Found; j := j + 1; end repeat then Found: index := j; NotThere: begin /* append value to array end */ arraySize := arraySize + 1; A[arraySize] := lookupValue; index := arraySize; end fi /* assert: A[index] = lookupValue */