O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Looping through Arrays

Obviously if you have an array of any substantial size, then working with its individual elements—as in the previous examples—quickly becomes tedious. This is even truer if the same process is used on each value (printing it, performing calculations with it, and forth). The easiest way to access every array element is to use a for loop.

You can review Chapter 4, “Control Structures,” for the syntax of a for loop, but normally there are four parts (Figure 6.6). The loop first initializes a variable to a value, and then checks that variable against another value as its condition. If that condition is true, certain statements are executed. Finally, the variable is incremented.

Figure 6.6. This flowchart reflects how for loops ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required