Objective-C Loop, Do Loop, While

June 15, 2009 § Leave a comment

// For Loop
for (int x = 0; x <10; x++) {
NSLog(@”x = %i, x”);
}

// Do Loop
x = 0;
do {
NSLog(@”x = @i”, x);
x++;
}
while (x  <= 10);

// While Loop
x = 0;
while (x  <=10) {
NSLog(@”x = %i”, x);
x++;
}

// For each loop
// Create a new array and add elements
NSMutableArray *sampleArray = [[NSMutableArray alloc] init];
[sampleArray addObjective:@”Element 1″];
[sampleArray addObjective:@”Element 2″];
[sampleArray addObjective:@”Element 3″];
[sampleArray addObjective:@”Element 4″];
[sampleArray addObjective:@”Element 5″];
for (NSString *s in sampleArray) {
NSLog(s);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Objective-C Loop, Do Loop, While at Web Builders.

meta

%d bloggers like this: