Changes

Jump to: navigation, search

Objective-C Looping - The for Statement

12 bytes removed, 19:27, 18 November 2009
no edit summary
In this chapter of [[Objective-C 2.0 Essentials]] we will continue looking at flow control in Objective-C applications. In the preceding chapters we have looked in detail at using logical expressions to decide what code should be executed. Another aspect of flow control entails the definition of loops. Loops are essentially sequences of Objective-C statements which are to be executed repeatedly until a specified condition (or conditions) are is met.
== Why Use Loops? ==
== Using for Loops with Multiple Variables ==
In the examples we have covered so far we have used a single variable within the ''for'' loop construct. Objective-C actually permits multiple variables to be modified within the looping process. In the following example, the for loop increments two variables, i and j:
<pre>
</pre>
Note that although both ''i'' and ''j'' are initialized and incremented in this loop, the number of times the loop is to be performed is still based on the value of ''i'' through the ''i > 10'' expression. The initialization and modification expressions for additional variables do not need to be the same as the control variable. For example, the following example initializes ''j'' to 5 and multiplies it by 2:
<pre>

Navigation menu