O'Reilly logo

Objective-C Quick Syntax Reference by Matthew Campbell

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

CHAPTER 11

image

While Loops

While Loops Defined

Like for loops, while loops are used when you want to repeat a similar type of task many times. While loops are used when you want to execute a line of code many times until a condition is met. Here is a while loop that will write to the console window 10 times:

int i = 0; while (i < 10) {    NSLog(@"i = %i", i);    i++;}

This while loop will produce this output:

i = 0i = 1i = 2i = 3i = 4i = 5i = 6i = 7i = 8i = 9

The loop above does the same thing as the for loop from Chapter 10, but note that the specifications for the loop are in different spots. The first thing that you will notice is that you need ...

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