Clearly Visual Basic: Programming with Visual Basic 2008
170 likes | 219 Views
Explore nested selection structures in Visual Basic 2008, including logical operators and algorithms for modified problem specifications. Learn how to apply logical and arithmetic operators effectively.
Clearly Visual Basic: Programming with Visual Basic 2008
E N D
Presentation Transcript
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
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
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
Download this interface from Dropbox: AddSub Solution If chkSubtraction.Checked = then If intNum1 > = intNum2 then intAnswer = intNum1-intNum2 Else intAnswer = intNum2-intNum1 End If Else intAnswer = intNum1 + intNum2 End If lblAnswer.Text = intAnswer
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
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
Summary (continued) • Logical operators • Can be included in an If…Then…Else statement’s condition • When the AndAlso logical operator is used to combine conditions: • All conditions must be True for the compound condition to be True • AndAlso operator • Has a higher precedence than the OrElse operator • Arithmetic operators • Evaluated first in an expression Clearly Visual Basic: Programming with Visual Basic 2008