Chapter 18. Programming Your App to Make Decisions: Conditional Blocks
Computers, even small ones like the phone in your pocket, are good at performing millions of operations in a single second. Even more impressively, they can also make decisions based on the data in their memory banks and logic specified by the programmer. This decision-making capability is probably the key ingredient of what people think of as artificial intelligence, and it’s definitely a very important part of creating smart, interesting apps! In this chapter, we’ll explore how to build this decision-making logic into your apps.
Chapter 14 discusses how an app’s behavior is defined by a set of event handlers. Each event handler executes specific functions in response to a particular event. The response need not be a linear sequence of functions, however; you can specify that some functions be performed only under certain conditions. For example, a game app might check if a player’s score has reached 100, or a location-aware app might ask if the phone is within the boundaries of some building. Your app can ask such questions and, depending on the answer, proceed accordingly.
Consider the diagram in Figure 18-1