Chapter 9. Using Control Statements and Loops

In This Chapter

  • Understanding how control statements and loops work

  • Knowing when to use — and not use — switch statements

  • Getting a handle on loop statements

  • Building your application

  • Using jump statements

In Chapter 7, I introduce you to NSMutableArrays to help you manage lists of objects. You see how you can use an array of objects and then iterate through the array, passing each object as an argument in a message. In Chapter 7, you use an array for only one transaction type, spendDollars: using one country's budget, europeBudget. If you want to extend that to chargeForeignCurrency:, you will need another array. And if you want to extend that to use englandBudget, you will need to add two additional arrays — one each for the spendDollars: and chargeForeignCurrency: messages.

This may seem pretty awkward, and it is. To manage my objects, what I really want is a single array that I can iterate through, one that holds all of the different transaction types for all of the countries I will be visiting.

And that's what you will be doing in this and the next chapter.

Along the way, I'll also complete your knowledge of the C functionality that is part of Objective-C — showing you how to use loops and control statements to determine the execution sequence of instructions.

Creating Transaction Objects

In order to start the journey to a single array that manages all of my transactions for all of the countries I visit, I want to review how the program works ...

Get Objective-C® For Dummies® 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.