Introduces DO, WHILE, SWITCH.
Uses type char and getchar()
Shows the ASCII representation of letters

/*wk4ex1.c*/ /*This introduces the use of the while loop. We use it to get an answer that is a correct value (1, 2, or 3). Look closely at the test in the while -- do you understand it? */

/*wk4ex2.c*/
/*This program uses the switch command in place of the if -- else logic used in the previous example.
The switch can replace a long string of if -- else statements */

/*wk4ex3.c*/
/*Here we replace scanf() with getchar().
We have changed choice to a char type and adjusted our switch to this.

Note: The scanf() shown as a comment below will still work -- it is just not how a programmer would do it. */

/*wk4ex4.c*/ /*This seems a simple example: you enter a letter and the program repeats the letter and shows its numeric code (ASCII value)
But what is the line:
getchar();
doing just before the while?
Remove the line and see what happens (a comment below explains it)
To help you, I will tell you that ASCII codes for things like carriage return, new line, and tab are low numbers (under 20)

HINT: an easy way to temporarily remove a statement is to turn it into a comment, so instead of erasing the line make it */

/*getchar();*/

/* This trick is called "commenting out" and is frequently used by programmers. */

/*wk4ex5.c*/


/*wk4ex6.c*/
/*This example is here because the book gives some bad advice. exercise 2 on page 71 suggests using for loops as timing (or time delay) devices. The program below pauses between letters using such a device.
DO NOT DO THIS!
You simply don't know how long the delay will be on different machines. I had to go to one million to get a reasonable delay on my machine. There are many old PC games which are unplayable today because the programmers used this kind of loop for timing a pause or response. On modern machines there is no discernable pause at all! */

/*wk4ex7.c*/


/*wk4ex8.c*/
/*This introduces the break command. Remember break ends the loop while continue just takes us to the top again.

/*wk4ex9.c*/

This page is at: http://testbed.cis.drexel.edu/Cindex4.html