December 2013
Intermediate to advanced
132 pages
1h 58m
English
CHAPTER 11
![]()
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 ...
Read now
Unlock full access