Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
While loops that count


1. While loops that count

2. Counting up
Here is a C program that counts up from 1 to 8.

Here is the C code.

Here is the output of the C code.

Here is a C program that counts up from 0 to 7.

Here is the C code.

Here is the output of the C code.


3. Counting down
Here is a C program that down from 8 to 1.

Here is the C code.

Here is the output of the C code.

Here is a C program that counts down from 7 to 0.

Here is the C code.

Here is the output of the C code.


4. Checking the loop
For beginning programmers, you should check your loop as follows. A professional programmer would determine the loop invariant and prove the loop correct for all possible cases, but that is beyond the scope of this course.

5. End of page