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 Cooln", i); } return 0; }
Note that in this simple loop example, you used the loop to dictate the number of times something happens. More commonly, however, loops are used to iterate through a collection of items, such as a list of names. For instance, you could modify this program to use a loop in conjunction with a list of friends’ names. Each time through the loop, a different friend would get to be cool. You will learn more about collections and loops starting in Chapter 17.