Download presentation
Presentation is loading. Please wait.
1
Controlling Program Flow
091700
2
Topics Conditional Operators Logical Operators If Select Case Loops
3
Operators manipulate data by combining or computing results.
4
Math and String Operators
Already Covered ( ) ^ * / \ MOD + - &
5
6 Conditional Operators
= Equal to < Less than > Greater than <> Not equal (less than or greater than) <= Less than or equal to >= Greater than or equal to NOTE: Errors is textbook table 6.1
6
You can compare strings
“S” < “s” “Kev” < “Kevin” ASCII table for character values Appendix C, page 888 IMPORTANT: The computer ultimately gives comparisons a TRUE or FALSE answer. print (1<2) print (1=2)
7
Like Operator Used for seeing if strings are similar
Uses Wildcards: * ? # [characters] [!not these characters] print “Kevin” like “Ke*” print “Boot” “B??t” print “Beet” like “B??t” print “Employee 7” like “Employee #” NOTE: Wildcard comparison has to be AFTER the like operator. Book is misleading here.
8
Logical Operators And Or Xor Not
9
And …Statements If (varA = varB) And (varC < varD) then End if
If True and True then Condition 1 AND Condition 2
10
Or …Statements If (varA = varB) Or (varC < varD) then End if
If True Or True then Condition 1 AND Condition 2
11
Xor …Statements If (varA = varB) Xor (varC < varD) then End if
If True Xor True then Condition 1 AND Condition 2
12
Not …Statements If Not((varA = varB) And (varC < varD)) then End if
NEGATES a condition Use Sparingly!
13
Truth Table Condition Result AND TRUE FALSE OR XOR
14
Such a simple device… Computers only know: 1 or 0 ON or OFF Yes or No
True or False We combine these choices to set the course of our computer program.
15
If then If (condition is true) then do this End if
16
If then Else If (condition is true) then do this Else
do something else End If
17
If then ElseIf If (condition is true) then do this
ElseIf (condition is true) then do something else Else do yet something else End If
18
Select Case Simpler, more logical than using several elses
Select Case varAge Case Is <5 statements Case 5 Case 6 to 11 Case 12 to 13, 23 to 46, Is 65 Case Else End Select
19
For Next Loop Used for counting through a certain number of iterations (geek-speak for times). For Counter = 1 to 10 statements Next
20
Nesting Loops For outerCounter = 1 to 10 statements
For innerCounter = 1 to 10 Next innerCounter Next outerCounter
21
Step value For counter = 0 to 10 step 2 statements Next
22
Step Values: negative For counter = 10 to 0 Step -1 statements Next
23
Do Loops Execute WHILE a condition is true, or UNTIL it is true
Do While strAnswer=“yes” statements Loop
24
Do Loops Do While Loop condition Until
25
Do Loops Do While condition statements Loop Do statements
Loop While condition Do Until condition statements Loop Do statements Loop Until condition
26
An early exit… Exit Sub Exit Function Exit For Exit Do
Use sparingly - It is most clear to have one exit for a program segment
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.