Discrete aths

•Objectives

–to show the use of induction for proving properties of code involving loops

•use induction to prove that functions work

–introduce pre- and post- conditions,

loop termination

2. Loop Invariants

Docsity.com

Overview

1. What is a Loop Invariant?

2. Three simple examples

–they involve while loops

3. Selection Sort

4. Further Information

Docsity.com

1. What is a Loop Invariant?

•A loop invariant is an inductive statement

which says something which is always true

about a program loop.

•Loop invariants are useful for:

–code specification

–debugging

continued

Docsity.com

•A loop invariant is typically written as an

inductive statement S(n), where n is some

changing element of the loop. For

example:

–the loop counter/index

–a loop variable which changes on each

iteration

Docsity.com

##### Document information

Uploaded by:
emee

Views: 3856

Downloads :
2

University:
Allahabad University

Subject:
Discrete Mathematics

Upload date:
27/04/2013