The for loop
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++) { ...
Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.