Iteration Implemented through loop constructs (e.g., in C++)

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
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.
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.
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
ISBN Chapter 8 Statement-Level Control Structures.
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
Chapter 8 (Control Structure) Slide 1 Control Structures Control structures are used by the programmer to incorporate the desired sequence of execution.
Chapter 5: Control Structures II (Repetition)
TODAY’S LECTURE Review Chapter 2 Go over exercises.
Fundamentals of Python: From First Programs Through Data Structures
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
CSE 425: Concurrency III Monitors A monitor is a higher level construct for synchronizing multiple threads’ access to a common code segment –Can implement.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
CSE 425: Syntax II Context Free Grammars and BNF In context free grammars (CFGs), structures are independent of the other structures surrounding them Backus-Naur.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
CSE 425: Concurrency II Semaphores and Mutexes Can avoid bad inter-leavings by acquiring locks –Guard access to a shared resource to take turns using it.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.
1 1 Additional Control Structures Chapter 9 2 New and Improved... Ways to branch Ways to write loops Understanding the break and continue statements.
Programming Logic and Design Fifth Edition, Comprehensive
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Chapter 6: Loops.
Names and Attributes Names are a key programming language feature
Chapter 4 C Program Control Part II
Python: Control Structures
Dr. Vamsi Paruchuri University of Central Arkansas
Statement-Level Control Structures
Lecture 14: Iteration and Recursion (Section 6.5 – 6.6)
CS1371 Introduction to Computing for Engineers
Think What will be the output?
Control Structures II (Repetition)
Chapter 5: Repetition Structures
CiS 260: App Dev I Chapter 4: Control Structures II.
Java Programming: Guided Learning with Early Objects
Chapter 6: Conditional Statements and Loops
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
Using the Priming Read Priming read (or priming input):
Control Structures - Repetition
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Loop Control Structure.
MSIS 655 Advanced Business Applications Programming
Statement-Level Control Structures
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
Control Flow Chapter 6.
Control Structures In Text: Chapter 8.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Understanding the Three Basic Structures
Algorithm Discovery and Design
Three Special Structures – Case, Do While, and Do Until
Parallelism and Concurrency
Statement-Level Control Structures
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Chapter8: Statement-Level Control Structures April 9, 2019
Introduction to Computer Science
Chapter 3: Selection Structures: Making Decisions
Presentation transcript:

Iteration Implemented through loop constructs (e.g., in C++) E.g., in C++, while, for, do loops A continue statement skips rest of that iteration of the loop A break statement exits the loop Iterators also provide helpful abstractions for iteration While loop Most basic construct: test guards each iteration of a block For loop Encodes special case of a while loop (can emulate an enumeration controlled loop using logical control) Do loop Ensures execution of the block at least once

Recursion Functional languages severely limit side effects Iteration relies on side effects to make progress, terminate Recursion is a natural alternative in those cases Or where avoiding side effects simplifies flow control logic Recursive functions can support lazy evaluation E.g., packaging up remaining work as a continuation and then only performing that work if it’s needed Normal order vs. applicative order evaluation Operands may not be evaluated until needed (applicative)

Nondeterminacy Features and Sources Dijkstra’s original guarded if statement Multiple alternate execution branches Each guarded by conditional expression, enabled if true Non-deterministic selection from among enabled statements Dijkstra’s guarded do statement Multiple guarded statements, enabled if guard evaluates true Repeated non-deterministic selection of enabled statement Multi-threading Deterministic sequencing within but not between threads Can synchronize to re-introduce inter-thread happens-before

Today’s Studio Exercises We’ll code up ideas from Scott Chapter 6.5-6.8 Looking at iteration, recursion, non-determinacy Today’s exercises are again in C++ C++ allows us to explore control flow issues for statements Functional languages rely more on function calls for control Please take advantage of the on-line tutorial and reference manual pages that are linked on the course web site As always, please ask us for help as needed When done, email your answers with subject line “Control Flow Studio II” to cse425@seas.wustl.edu