Nesting If...Else Statements
If you nest one If...Else statement inside another, you'll have to use ElseIf to start the nested statement. Consider the code in Listing 8.2.
Code Listing 8.2. Combining Nested If...Else Statements with ElseIf
If (intHours <= 40) Then curOverTime = 0.0 'Now test for hours between 40 and 50 'and pay time and a half ElseIf (intHours <= 50) Then curOverTime = (intHours - 40) * 1.5 * sngRate Else 'Must pay double time over 50 and 'time and a half for the hours between '40 and 50 curOverTime = ((intHours - 50) * 2 + (10 * 1.5)) * sngRate End If |
The ElseIf statement in the fifth line starts a new If...Else block of code. If the value of intHours is not 40 or less in the first line, it must be more than 40. Therefore, ...
Get Absolute Beginner's Guide to Programming, Second 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.