The program in the CPIC uses a while loop to make the value in count get larger and larger. Because the value 1 is always true (which we remember from our discussion on conditions above) we find that the block of code which follows the while is executed forever. Note that the syntax for the while construction is usually:

while ( condition ) statement ;

I have made the statement which follows the while statement into a block so that I can perform many statements if I wish. I tend to use blocks even when they are not required, since it makes it easier for me to add further statements later, and I also think it makes the program clearer.

Note the way that the program works, in that the condition is tested before the statement is executed. This means that if the condition is false to start with, the statement is never performed:

while ( 0 )
{
    /* code placed here        */
    /* will never be executed  */
}

Sometimes you want to do something at least once, and then repeat the action if required. C has a construction which lets you do this:

do
{
  /*  code placed here will      */
  /* be performed at least once  */
} while ( condition ) ;

The code in the block is obeyed and the condition is then tested. If the condition is true the loop repeats. I use this to get input from a user. Inside the do loop I read the user input, then I test it to make sure that it is OK. If the input is duff I go around again:

do {
  /* get the input from the user */
} while ( true if input is duff ) ;

If you like you can put loops inside loops, at which point I hope you will continue to use the indenting technique to see which is which.