Page 132 - Open Soource Technologies 304.indd
P. 132
Event Driven Programming
6.2 If- else Blocks
An If block allows a program to decide on a course of action based on whether certain conditions
are true or false.
6.2.1 If Block
A block of the form:
If condition Then
action1
else
action2
end If
causes the program to take action1 If condition is true and action2 If condition is false. Each action
consists of one or more Visual Basic statements. After an action is taken, execution continues with
the line after the If block. Figure 6.1 contains the pseudocode and flowchart for an If block.
No Is the Yes
condition
If condition is true Then true?
Processing step (s0 1
Else
Processing step (s) 2 Execute Execute
End If processing Step (s) 2 processing Step (s) 1
Figure 6.1: Pseudocode and Flowchart for an If Block.
1: The following program finds the larger of two numbers input by the user.
The condition is
num1 > num2
126 LOVELY PROFESSIONAL UNIVERSITY