Repetition (Loops)

6/11/99


Click here to start


Table of Contents

Repetition (Loops)

Outline

Repetitions with Loops

Types of Loops

PreTest vs. PostTest Loops

Terminating Loops

Counter-Controlled Loops

Event-Controlled Loops

Parts of Loop

Parts of Loop Example

Importance of Update

Infinite Loops

Termination Conditions in C

Pretest Loop: While

Example of While

Executing More Than One Stmt

Empty Statements and Loops

Event-Controlled While

Calculate Average Loop

Calculate Average Code

Using a Sentinel

Compound Conditions

Making Sure Loop is Entered

Posttest Loop: Do-While

Using the Do-While

Programs with Menus

Menu Loop

Menu Options

Executing Options

While vs Do-While

Pretest Loop: For

For Loop

For Example

For Example - Sum of 1 to N

For Example - Max of N Scores

The Comma Form

Directions of Counting

Nesting Loops

Tracing Nested Loops

More Efficient Implementation

Another Nesting Example

More Complex Nesting

Another Nesting Example

Nesting and Functions

break statement

Flags

continue statement

Avoiding continue

Author: Richard Maclin

Email: rmaclin@d.umn.edu

Home Page: http://www.d.umn.edu/~rmaclin/

Download presentation source