Chapter 3- Data Types and Operators Boolean Expressions Page 2 3 4

Introduction

The If Statement Page 2 3 4 5 6 7 8 9
Arithmetic Operations Page 2 3 4 5 6 Boolean Operators and Nested If Statements Page 2 3 4 5 6 7
Events and Sequential Processing Page 2 3 4 5 More Examples Page 2 3 4 5 6 7 8 9 10 11 12
Datatypes and Conversions Page 2 3 4 5 6 7 Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10
Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Exercises Page 2 3 4 5 6 7 8
Chapter 4- Selection Statements Review Questions
Introduction

4-3: If Statements

The Else Statement

Often a decision involves a choice between doing two things. For example,

If (timeAvailable < 10 minutes) Then
drive car
Else
ride bicycle
End If

The simple If statement discussed in the previous section can be expanded in just this way, i.e. by including the Else keyword followed on a new line by at least one statement. We'll see examples shortly.

The ElseIf Statement

Extending these ideas further, it is also possible that a decision involves more than two options. For example

If (Age < 15 ) Then
ticketPrice = 10
ElseIf (Age < 65) Then
ticketPrice = 15
Else
ticketPrice = 12
End If

The syntax in this case requires the keyword ElseIf followed by a boolean value (in the example, the boolean value is the result of the expression) and the keyword Then. There must then be at least one statement on a new line.