Beruflich Dokumente
Kultur Dokumente
Conditional Statement
6
Lecture 1
Operators
Relational Operators
>
<
>=
<=
<>
=
Greater than
Less than
Greater than or equal to
Less than or equal to
Not Equal to
Equal to
Logical Operators
AND, OR
Lecture 6
Example
A = 1,
1 B = 2,
2 C = 3,
3 D=4
A>B
B <> C
A
A
A
A
A
A
=
>
>
=
>
>
1
B
B
1
B
B
FALSE
TRUE
OR B <> C
OR B <> C
OR B = C
AND B <> C
AND B <> C
AND B = C
D=4
B >= 2
T
F
F
T
F
F
OR T
OR T
OR F
AND T
AND T
AND F
Lecture 6
TRUE
TRUE
TRUE
TRUE
FALSE
TRUE
FALSE
FALSE
If then if CONTROL
Basic If statement
If Ans =1 Then
(statement for TRUE)
End If
If Ans1 = 1 Then
(statement
( t t
t for
f TRUE)
Else
(statement for FALSE)
End If
Lecture 6
If then: Example
If End if
If Rad < 0 Then
MsgBox Radius must be positive
Message = Radius of the circle "
Title = "InputBox"
InputBox
Default = 10.0"
Rad = InputBox(Message, Title,Default)
End If
Lecture 6
End If
Note: use tab to differentiate the level of If
Lecture 6
counter initialization
Lecture 6
Sub main()
Dim Counter, Total As Integer
Counter = 0
Total = 0
While Counter < 11
Total = Total + Counter
Counter = Counter + 1
Wend
g
" Total number 1 to 10 is " & Val(Total)
(
)
MsgBox
End Sub
Lecture 6
10
number"
End Select
Lecture 6
12
Task: continued
D
Draw the
th user has
h the
th choice
h i the
th
draw the polygon
Lecture 6
13
Array
Lecture 6
14
Lecture 6
15
End Sub
Lecture 6
16