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 12

image

Do While Loops

Do While Loops Defined

Do while loops are used for the same reasons as for loops and while loops. The syntax is different, and do while loops are notable because the code in the block will execute at least once. This is because the ending condition is not evaluated until the end of the loop. Here is how you would code a do while loop to count to 10:

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

This do 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 and the while loop in Chapter 11. The specifications ...

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