Boolean Expressions

Sometimes a programmer would like a statement, or group of statements to execute only if certain conditions are true. There may be a different statement, or group of statements that are to be executed when the condition is false. An expression that can be evaluated to true or false is called a Boolean expression. (Named after a mathematician named Boole.)

Examples of Boolean Expressions:  (X and Y are variables)

X = 5 (True if X has a value equal to 5)
X > Y(True if X is greater than Y; example X is 7, Y is 3)
X < Y(True if X is less than Y; example X is 2, Y is 2.5)
X <> Y(True if X is not equal to Y; example X is 5, Y is 6)
X >= Y(X is greater than or equal to Y; example X is 4, Y is 3 or 4)
X <= Y(X is less than or equal to Y; example X is 4, Y is 4 or 5)

The IF Statement

If you want to execute one or more statements when a Boolean expression is true use the format shown below:

  If Boolean  exp. Then 
     statement 1      statement      ...    Else      false statement 1      false statement     ...   End If

The Else section is optional;. If there are no statements to execute when the Boolean expression is false, you may leave out the else section.


INDEX, IF Statements, Top or bottom?, AND And OR, Left or Right?
Next lesson: Drawing in Visual Basic

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

IF Statements