Nested for Loops
Program 5.4 gives the user the flexibility to have the program calculate any triangular number that is desired. But suppose the user has a list of five triangular numbers to be calculated? In such a case, the user could simply execute the program five times, each time typing in the next triangular number from the list to be calculated.
Another way to accomplish the same goal, and a much more interesting method, as far as learning about Objective-C is concerned, is to have the program handle the situation. You can best accomplish this by inserting a loop into the program to repeat the entire series of calculations five times. You can use the for statement to set up such a loop. Program 5.5 and its associated output illustrate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access