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 ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.