November 2013
Beginner
325 pages
9h 47m
English
The while loop is a general looping structure, but C programmers use the same basic pattern a lot:
some initialization
while (some check) {
some code
some last step
}
So, the C language has a shortcut: the for loop. In the for loop, the pattern shown above becomes:
for (some initialization; some check; some last step) {
some code;
}
Change the program to use a for loop:
#include <stdio.h>
int main(int argc, const char * argv[])
{
for (int i = 0; i < 12; i++) {
printf("%d. Aaron is Cool\n", i);
}
return 0;
}
Note that in this simple loop example, you used the loop to dictate the number of times something ...
Read now
Unlock full access