September 1998
Intermediate to advanced
848 pages
20h 13m
English
The for loop gathers all three actions into one place. By using a for loop, you can replace the preceding program with the one shown in Listing 6.9.
/* sweetie2.c -- a counting loop using for */
#include <stdio.h>
#define NUMBER 22
int main(void)
{
int count;
for (count = 1; count <= NUMBER; count++)
printf("Be my Valentine!\n");
return 0;
}
|
The parentheses following the keyword for contain three expressions separated by two semicolons. The first expression is the initialization. It is done just once, when the for loop first starts. The second expression is the test condition; it is evaluated before each potential execution of a loop. When the expression is false (when count is greater than ...
Read now
Unlock full access