Lecture 8: Control Structures

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

College of Information Technology & Design
Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
Lecture 24 MAS 714 Hartmut Klauck
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
The Flow of Control Among Statements.  Selection Statements  Iterative Statements  Unconditional Branching  Guarded Commands.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 6.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Discrete Mathematics Lecture 4 Harper Langston New York University.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
CSE 830: Design and Theory of Algorithms
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Describing Syntax and Semantics
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
Simple Program Design Third Edition A Step-by-Step Approach
CPS120: Introduction to Computer Science Decision Making in Programs.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
CIS 234: LOOPS Adapted from materials by Dr. Donald Bell, 2000 (updated April 2007)
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Algorithm Design.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Chair of Software Engineering Complement to lecture 11 : Levenshtein.
Algorithms 1.Notion of an algorithm 2.Properties of an algorithm 3.The GCD algorithm 4.Correctness of the GCD algorithm 5.Termination of the GCD algorithm.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 8: Control Structures I.
Department of Computer Science, York University Object Oriented Software Construction 22/01/ :58 AM 1 COSC3311 – Software Design Loop invariant/variant.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Introduction to Turing Machines
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
CSE15 Discrete Mathematics 03/06/17
Applied Discrete Mathematics Week 2: Functions and Sequences
REPETITION CONTROL STRUCTURE
Analysis of Algorithms
Data Structures and Algorithms
GC211Data Structure Lecture2 Sara Alhajjam.
Representation, Syntax, Paradigms, Types
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Quick Test What do you mean by pre-test and post-test loops in C?
Introduction to Computer Programming
Chapter 4 Control structures and Loops
CSS161: Fundamentals of Computing
Lecture 2: Axiomatic semantics
Objective of This Course
Axiomatic semantics Points to discuss: The assignment statement
Representation, Syntax, Paradigms, Types
Algorithm Discovery and Design
Representation, Syntax, Paradigms, Types
Complement to lecture 11 : Levenshtein distance algorithm
Instructor: Aaron Roth
Representation, Syntax, Paradigms, Types
Application: Algorithms
Lecture 2: Axiomatic semantics
Selamat Datang di “Programming Essentials in Python”
Chapter 4: Loops and Iteration
Presentation transcript:

Lecture 8: Control Structures Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 8: Control Structures

In this (double) lecture The notion of algorithm Basic control structures: sequence, conditional, loop Decision structures: variants of conditional instruction Repeating operations: the loop Loops as approximation strategy: the loop invariant What does it take to ensure that a loop terminates? A look at the general problem of loop termination Lower-level control structures: “Goto” and flowcharts; see rationale for the “control structures of Structured Programming” Undecidability of the Halting Problem

The notion of algorithm General definition: An algorithm is the specification of a process to be carried out by a computer

Not quite an algorithm

5 properties of an algorithm 1. Defines data to which process will be applied 2. Every elementary step taken from a set of well-specified actions 3.Describes ordering(s) of execution of these steps 4. 2 and 3 based on precisely defined conventions, suitable for execution by an automatic computer 5. For any data, guaranteed to terminate after finite number of steps

Algorithm vs program “Algorithm” usually considered a more abstract notion, independent of platform, programming language etc. In practice, the distinction tends to fade: Algorithms need a precise notation Programming languages becoming more abstract However: In programs, data (objects) are just as important as algorithms A program typically contains many algorithms and object structures

What makes up an algorithm Basic steps: Feature call x.f (a ) Assignment ... Sequencing of these basic steps: CONTROL STRUCTURES

Control structures Definition: program construct that describes the scheduling of basic actions Three fundamental control structures: Sequence Loop Conditional They are the “Control structures of Structured Programming”

Control structures as problem-solving techniques Sequence: “To achieve C from A, first achieve an intermediate goal B from A, then achieve C from B” Loop: solve the problem on successive approximations of its input set Conditional: solve the problem separately on two or more subsets of its input set

The sequence (or Compound) instruction 1 instruction 2 ... instruction n

Semicolon as optional separator instruction1 ; instruction2 ; ... ; instructionn

Not quite an algorithm

Correctness of a Compound Precondition of instruction 1 must hold initially Postcondition of each instruction i must imply precondition of each instruction i + 1 Final effect is postcondition of instruction n

Conditional instruction if Condition then Instructions else Other_instructions end -- Boolean_expression -- Compound -- Compound

Computing the greater of two numbers if a > b then max := a else max := b end

As a query maximum (a, b : INTEGER): INTEGER -- The higher of a and b. do if a > b then Result := a else Result := b end end

The conditional as problem-solving technique PROBLEM SPACE Region 2 Use technique 2 Region 1 Use technique 1

Basic form if Condition then Instructions else Other_instructions end

A variant of the conditional if Condition then Instructions end

A variant of the conditional if Condition then Instructions end Means the same as if Condition then Instructions else end Empty clause

if Condition1 then Instructions1 else end ... Nesting

Nested structure

Comb-like structure

Comb-like conditional if Condition1 then Instructions 1 elseif Condition 2 then Instructions 2 elseif Condition3 then Instructions 3 elseif ... else Instructions 0 end

Comb-like structure

More control structure topics Loops and their invariants See what it takes to ensure that a loop terminates Look at the general problem of loop termination Examine lower-level control structures: “Goto” and flowcharts; see rationale for the “control structures of Structured Programming” Prove the undecidability of the Halting Problem

Loop from Initialization -- Compound variant Variant_expression -- Integer expression invariant Invariant_expression -- Condition until Exit_condition -- Boolean_expression loop Body -- Compound end

Loop, full form from Initialization -- Compound invariant Invariant_expression -- Boolean_expression variant Variant_expression -- Integer_expression until Exit_condition -- Boolean_expression loop Body -- Compound end

Another loop syntax

Loop, full form from Initialization -- Compound invariant Invariant_expression -- Boolean_expression variant Variant_expression -- Integer_expression until Exit_condition -- Boolean_expression loop Body -- Compound end

Looping over stations of a line Previously and in the textbook: fancy_line from fancy.start until fancy.after loop -- “Do something with fancy.item” fancy.forth end

Operations on a list (The cursor) before after item index count start 1 index count start back forth Commands Queries (The cursor) (boolean)

Operations on a list (The cursor) before after item index count start 1 index count start forth (The cursor)

Looping over stations of a line from fancy.start until fancy.after loop -- “Do something with fancy.item” fancy.forth end

Displaying station names from fancy.start until fancy.after loop -- Display name of next station: Console.show (fancy.item) fancy.forth end

Computing the “maximum” of station names from fancy.start ; Result := "" until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Assignment Result := "XYZ " -- Change the value of Result to "XYZ "

Computing the “maximum” of station names from fancy.start ; Result := " " until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end The greater of two strings, alphabetically, e.g. greater ("ABC ", "AD ") = "AD"

In a function highest_name: STRING -- Alphabetically greatest station name of line do from fancy.start ; Result := "" until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Postcondition? highest_name: STRING -- Alphabetically greatest station name of line do from fancy.start ; Result := "" until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end ensure Result /= Void and then not Result.empty

Loop as approximation strategy name 1 name 2 name i name n .. Loop body: Result = name 1 = Max (names 1 1) .. i := i + 1 Result := greater (Result , fancy.item.name) Result = Max (names 1 2) Slice .. Result = Max (names 1 i ) .. Result = Max (names 1 n )

Computing the “maximum” of station names from fancy.start ; Result := "" until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

The loop invariant from fancy.start ; Result := "" invariant fancy.index >= 1 fancy.index <= fancy.count + 1 -- Result is the alphabetically highest of the -- names of previous stations until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Loop as approximation strategy name 1 name 2 name i name n .. Loop body: Result = name 1 = Max (names 1 1) .. i := i + 1 Result := greater (Result , fancy.item.name) Result = Max (names 1 2) .. Result = Max (names 1 i ) .. Result = Max (names 1 n ) The loop invariant

Loop invariant (Do not confuse with class invariant) Property that is: Satisfied after initialization (from clause) Preserved by every loop iteration (loop clause) executed with the exit condition (until clause) not satisfied

.. The loop invariant from fancy.start ; Result := "" invariant fancy.index >= 1 fancy.index <= fancy.count + 1 -- Result is the alphabetically highest of the -- names of previous stations until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end .. Result = Max (names 1 n )

The loop invariant (better) from fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- If there are any previous stations, -- Result is the alphabetically highest of their names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Loop as approximation strategy name 1 name 2 name i name n .. Loop body: Result = name 1 = Max (names 1 1) .. i := i + 1 Result := greater (Result , fancy.item.name) Result = Max (names 1 2) .. Result = Max (names 1 i ) .. Result = Max (names 1 n ) The loop invariant

In a function highest_name : STRING -- Alphabetically greatest station name of line do from fancy.start ; Result := "" until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Postcondition? highest_name: STRING -- Alphabetically greatest station name of line do from fancy.start ; Result := "" until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end ensure Result /= Void and then not Result.empty

Loop as approximation strategy name 1 name 2 name i name n .. Loop body: Result = name 1 = Max (names 1 1) .. i := i + 1 Result := greater (Result , fancy.item.name) Result = Max (names 1 2) .. Result = Max (names 1 i ) .. Result = Max (names 1 n ) The loop invariant

The loop invariant from fancy.start ; Result := "" invariant fancy.index >= 1 fancy.index <= fancy.count + 1 -- Result is the alphabetically highest of the -- names of previous stations until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Loop invariant (Do not confuse with class invariant) Property that is: Satisfied after initialization (from clause) Preserved by every loop iteration (loop clause) when executed with the exit condition (until clause) not satisfied

The loop invariant from fancy.start ; Result := "" invariant fancy.index >= 1 fancy.index <= fancy.count + 1 -- Result is highest of previous station names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

The loop invariant (better) from fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- If there are any previous stations, -- Result is the alphabetically highest of their names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Loops as problem-solving strategy A loop invariant is a property that: Is easy to establish initially (even to cover a trivial part of the data) Is easy to extend to cover a bigger part If covering all data, gives the desired result!

The effect of the loop from Invariant satisfied after initialization fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- Result is highest of previous station names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end Invariant satisfied after initialization Invariant satisfied after each iteration Exit condition satisfied at end At end: invariant and exit condition All stations visited (fancy.after ) Result is highest of their names

Quiz: what’s the invariant? xxx (a, b: INTEGER): INTEGER is -- ????????????????????????????????? require a > 0 ; b > 0 local m, n : INTEGER do from m := a ; n := b invariant -- “????????” variant ???????? until m = n loop if m > n then m := m − n else n := n − m end Result := m

Quiz: what’s the invariant? xxx (a, b: INTEGER): INTEGER is -- ????????????????????????????????? require a > 0 ; b > 0 local m, n : INTEGER do from m := a ; n := b invariant -- “????????” variant ???????? until m = n loop if m > n then m := m − n else n := n − m end Result := m

Quiz: what’s the invariant? euclid (a, b: INTEGER): INTEGER is -- Greatest common divisor of a and b require a > 0 ; b > 0 local m, n : INTEGER do from m := a ; n := b invariant -- “????????” variant ???????? until m = n loop if m > n then m := m − n else n := n − m end Result := m

M I I C H H A A E L J A C K S O N E N D S H Another example 1 2 3 4 5 “Michael Jackson” to “Mendelssohn” M I I C H H A A E L J A C K S O N E N D S H S D S S S D D D D I Operation Distance 1 2 3 4 5 6 7 8 9 10 Intro. to Programming, lecture 11 (complement): Levenshtein 61

B B E E E E T T H H O O V V E E N N A L S Levenshtein distance 1 1 2 3 “Beethoven” to “Beatles” B B E E E E T T H H O O V V E E N N A L S Operation R D R D R Distance 1 1 2 3 4 4 5 62

Levenshtein distance Also called “Edit distance” Purpose: to compute the smallest set of basic operations Insertion Deletion Replacement that will turn one string into another Intro. to Programming, lecture 11 (complement): Levenshtein 63

B E A T L E S 1 2 3 4 5 6 7 1 2 3 4 5 6 7 B 1 1 1 2 3 4 5 6 E 2 2 1 1 2 3 4 5 E 3 3 2 1 1 2 3 3 4 T 4 4 3 2 2 1 2 3 4 H 4 5 5 4 3 3 2 2 3 4

Levenshtein distance algorithm distance (source, target: STRING): INTEGER -- Minimum number of operations to turn source into target local dist : ARRAY_2 [INTEGER] i, j, del, ins, subst : INTEGER do create dist.make (source.count, target.count) from i := 0 until i > source.count loop dist [i, 0] := i ; i := i + 1 end from j := 0 until j > target.count loop dist [0, j ] := j ; j := j + 1 end -- (Continued) 65

Levenshtein distance algorithm from i := 1 until i > source.count loop from j := 1 until j > target.count invariant loop if source [i ] = target [ j ] then dist [i, j ] := dist [ i -1, j -1] else deletion := dist [i -1, j ] insertion := dist [i , j - 1] substitution := dist [i - 1, j - 1] dist [i, j ] := minimum (deletion, insertion, substitution) + 1 end j := j + 1 i := i + 1 Result := dist (source.count, target.count) ??? 66

How do we know a loop terminates? from fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- If there are any previous stations, -- Result is the alphabetically highest of their names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

How do we know a loop terminates? from fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- If there are any previous stations, -- Result is the alphabetically highest of their names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Loop variant Integer expression that must: Be non-negative when after initialization (from) Decrease (i.e. by at least one), while remaining non-negative, for every iteration of the body (loop) executed with exit condition not satisfied

The variant for our example from fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- If there are any previous stations, -- Result is the alphabetically highest of their names variant until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end fancy.count − fancy.index + 1

The general termination problem Can EiffelStudio find out if your program will terminate? No, it can’t  No other program, for any other realistic programming language, can!   

The halting problem and undecidability (“Entscheidungsproblem”, Alan Turing, 1936.) It is not possible to devise an effective procedure that will find out if an arbitrary program will terminate on arbitrary input (or, for that matter, if an arbitrary program with no input will terminate)

The halting problem in Eiffel Assume we have a feature terminates (my_program: STRING ): BOOLEAN -- Does my_program terminate? do ... Your algorithm here ... end

The halting problem in practice Some programs do not terminate in certain cases... That’s a bug! Yours had better terminate in all cases Use variants

Another loop syntax

How do we know a loop terminates? from fancy.start ; Result := "" invariant index >= 1 index <= count + 1 -- If there are any previous stations, -- Result is the alphabetically highest of their names until fancy.after loop Result := greater (Result, fancy.item.name) fancy.forth end

Control structures at the machine level Unconditional branch: BR label Conditional branch, for example: BEQ loc_a loc_b label

The equivalent of if-then-else if a = b then Compound_1 else Compound_2 end BEQ loc_a loc_b 111 101 ... Code for Compound_2 ... BR 125 111 ... Code for Compound_1 ... 125 ... Code for continuation of program ...

Flowcharts True False

In programming languages: the Goto test condition goto else_part Compound_1 goto continue else_part : Compound_2 continue : ... Continuation of program ... True False

“Goto considered harmful” Dijkstra, 1968 Arbitrary Goto instructions lead to messy, hard to maintain programs (“spaghetti code”) Böhm and Jacopini theorem: any program that can be expressed with goto instructions and conditionals can also be expressed without gotos, using sequences, conditionals and loops For an example of transformation see Touch of Class

The Goto today Almost universally decried Still exists in some programming languages Also hides under various disguises, e.g. break loop ... if c then break end end

One-entry, one-exit (Compound) (Loop) (Conditional)

Quiz: what’s the invariant? xxx (a, b: INTEGER): INTEGER is -- ????????????????????????????????? require a > 0 ; b > 0 local m, n : INTEGER do from m := a ; n := b invariant -- “????????” variant ???????? until m = n loop if m > n then m := m − n else n := n − m end Result := m

Quiz: what’s the invariant? euclid (a, b: INTEGER): INTEGER is -- Greatest common divisor of a and b require a > 0 ; b > 0 local m, n : INTEGER do from m := a ; n := b invariant -- “????????” variant ???????? until m = n loop if m > n then m := m − n else n := n − m end Result := m

Levenshtein distance Also called “Edit distance” Purpose: to compute the smallest set of basic operations Insertion Deletion Replacement that will turn one string into another Intro. to Programming, lecture 11 (complement): Levenshtein 86

B E A T L E S 1 2 3 4 5 6 7 1 2 3 4 5 6 7 B 1 1 1 2 3 4 5 6 E 2 2 1 1 2 3 4 5 E 3 3 2 1 1 2 3 3 4 T 4 4 3 2 2 1 2 3 4 H 4 5 5 4 3 3 2 2 3 4

Levenshtein distance algorithm distance (source, target: STRING): INTEGER -- Minimum number of operations to turn source into target local dist : ARRAY_2 [INTEGER] i, j, del, ins, subst : INTEGER do create dist.make (source.count, target.count) from i := 0 until i > source.count loop dist [i, 0] := i ; i := i + 1 end from j := 0 until j > target.count loop dist [0, j ] := j ; j := j + 1 end -- (Continued) 88

Levenshtein distance algorithm from i := 1 until i > source.count loop from j := 1 until j > target.count invariant loop if source [i ] = target [ j ] then dist [i, j ] := dist [ i -1, j -1] else deletion := dist [i -1, j ] insertion := dist [i , j - 1] substitution := dist [i - 1, j - 1] dist [i, j ] := minimum (deletion, insertion, substitution) + 1 end j := j + 1 i := i + 1 Result := dist (source.count, target.count) -- For all p : 1 .. i, q : 1 .. j –1, we can turn source [1 .. p ] -- into target [1 .. q ] in dist [p, q ] operations ??? 89

The halting problem and undecidability (“Entscheidungsproblem”, Alan Turing, 1936.) It is not possible to devise an effective procedure that will find out if an arbitrary program will terminate on arbitrary input (or, for that matter, if an arbitrary program with no input will terminate)

The halting problem in Eiffel Assume we have a feature terminates (my_program: STRING ): BOOLEAN -- Does my_program terminate? do ... Your algorithm here ... end

Paradoxes in logic The Russell paradox Some sets are members of themselves, e.g. the set of all infinite sets is infinite Others are not members of all sets, e.g. the set of all finite sets is not finite Consider the set of all sets that are not members of themselves The barber paradox (Russell) In Zurich there is a hairdresser that does the hair of all the inhabitants who do not do their own hair Who does her hair?

The Grelling paradox An adjective in English is: “Autological” is if applies to itself (e.g. “polysyllabic”) “Heterological” otherwise What is the status of “Heterological”? Another form: The first proposition appearing in red on this page is false

The liar’s paradox (Very old!) Epaminondas says all Cretans are liars Epaminondas is a Cretan

The halting problem and undecidability (“Entscheidungsproblem”, Alan Turing, 1936.) It is not possible to devise an effective procedure that will find out if an arbitrary program will terminate on arbitrary input (or, for that matter, if an arbitrary program with no input will terminate)

The halting problem in Eiffel Assume we have a feature string_terminates (my_program : STRING): BOOLEAN -- Does my_program terminate? do ... Your algorithm here ... end

The halting problem in Eiffel Then we can write terminates (file_name : STRING): BOOLEAN -- Does program in file file_name terminate? do ... Your algorithm here ... end

Then… Root procedure of the system: what_do_you_think -- Terminate only if not do from until not terminates (“/usr/home/myfile”) loop end Then copy the program text to /usr/home/myfile

The halting problem in practice Some programs do not terminate in certain cases... That’s a bug! Yours had better terminate in all cases Use variants

What we have seen The notion of algorithm Basic properties Difference with “program” The notion of control structure Correctness of an instruction Control structure: sequence Control structure: conditional Nesting, and how to avoid it