Using Conditional Statements and Loops
This chapter is all about controlling your application. For the most part, the examples so far have run straight through a procedure—a particular set of steps for performing a task. However, the real world doesn't work that way and neither can your application. As you perform tasks, you make decisions and sometimes need to perform a task more than once—such as write the check, place it in the envelope, seal the envelope, add postage, repeat until bills are paid. The decision- making part of an application is called a conditional statement, while the repetitive part is called a loop.
Both conditional statements and loops provide organization for your application. In fact, most developers call them structures. For example, you use an If . . . Then structure to hold code that conditionally executes based on the condition you provide. Structures are an essential part of applications and they come in many forms, as you'll discover as the book progresses.
Making Decisions Using the If . . . Then . . . Else Statement
The bread and butter of decision making for the developer is the If . . . Then statement. In fact, you've already seen this statement in use in some of the examples in previous chapters. The following sections describe the various forms of the If . . . Then statement.
Using If . . . Then Alone
The If . . . Then statement is the most basic form of conditional statement that you can use. You use it to optionally execute code ...