Clearly Visual Basic Programming with Visual Basic 2008
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 10 Time to Leave the Nest
Objectives • Nest selection structures • Include logical operators in a selection structure’s condition Clearly Visual Basic: Programming with Visual Basic 2008 2
Nested Selection Structures • Nested selection structure – Selection structure contained (nested) within an outer structure • Figure 10 -1 – Shows problem specification and its algorithm • Figure 10 -2 – Shows modified problem specification along with modified algorithm • Figure 10 -3 – Shows correct algorithm Clearly Visual Basic: Programming with Visual Basic 2008 3
Clearly Visual Basic: Programming with Visual Basic 2008 4
Clearly Visual Basic: Programming with Visual Basic 2008 5
Clearly Visual Basic: Programming with Visual Basic 2008 6
Putting Rob’s Problem Aside • Figure 10 -5 – Shows correct algorithm for problem – Consider how you would change the algorithm • Figure 10 -6 – Shows modified problem specification and its algorithm Clearly Visual Basic: Programming with Visual Basic 2008 7
Clearly Visual Basic: Programming with Visual Basic 2008 8
Clearly Visual Basic: Programming with Visual Basic 2008 9
Download this interface from Dropbox: Add. Sub Solution If chk. Subtraction. Checked = then If int. Num 1 > = int. Num 2 then int. Answer = int. Num 1 -int. Num 2 Else int. Answer = int. Num 2 -int. Num 1 End If Else int. Answer = int. Num 1 + int. Num 2 End If lbl. Answer. Text = int. Answer
That’s Way Too Logical for Me • Logical operators (Boolean operators) – Allow you to combine two or more conditions into one compound condition – Always evaluated after any comparison operators in an expression • Arithmetic operators – Evaluated first in an expression Clearly Visual Basic: Programming with Visual Basic 2008 11
Clearly Visual Basic: Programming with Visual Basic 2008 12
Clearly Visual Basic: Programming with Visual Basic 2008 13
Clearly Visual Basic: Programming with Visual Basic 2008 14
Clearly Visual Basic: Programming with Visual Basic 2008 15
Summary • Both paths in a selection structure: – Can include nested selection structures • Nested selection structures – Used when more than one decision must be made before the appropriate action can be taken • When comparing two numbers: – The first number can be greater than, less than, or equal to the second number Clearly Visual Basic: Programming with Visual Basic 2008 16
Summary (continued) • Logical operators – Can be included in an If…Then…Else statement’s condition • When the And. Also logical operator is used to combine conditions: – All conditions must be True for the compound condition to be True • And. Also operator – Has a higher precedence than the Or. Else operator • Arithmetic operators – Evaluated first in an expression Clearly Visual Basic: Programming with Visual Basic 2008 17
- Slides: 17