More Loops

4/14/99


Click here to start


Table of Contents

More Loops

Counter-Controlled Repetition with a while loop

The for loop Repetitive Structure

When does the for loop initialize, test and modify ?

A for loop that counts from 0 to 10

We can count backwards, too

We can count by 2’s ... or 7’s ... or whatever

The do-while repetitive structure

do-while example

A while that tests input Compare with do-while

for vs while

for loops for specified number of iterations

use while when a condition terminates your loop

while vs do-while

break

Example break in a loop

continue

Example of continue in a loop

Nested for loops

The char data type

Character Example

The getchar ( ) function

getchar () example

Author: UMBC Dennis

Email: frey@cs.umbc.edu