Visual Basic includes a number of features that allow us to select among alternative pathways,or to repeat the execution of a particular block of statements. For example, we can choose toexecute one of several different blocks of statements, depending on the value of anexpression. This process is known as
. Or, we can choose one of two different paths,depending on the outcome of a logical test (i.e., depending whether a
). This process is known as
.Many programs require that a group of instructions be executed repeatedly, until someparticular condition has been satisfied. This process is known as
. Sometimes thenumber of passes through the loop will be known in advance (
looping). In othersituations the looping action will continue indefinitely, until some logical condition has beensatisfied (
looping).In order to carry out branching operations in Visual Basic, we must be able to expressconditions of equality and inequality. To do so, we make use of the following
NameVisual Basic Comparison Operator Sample Expression Meaning
=m = cm is equal to c
<>m <> cm is not equal toc
>m > cm is greater thanc
<m < cm is less than c
Greater than or equal to
>=m >= cm is greater thanor equal to c
Less than or equal to
<=m <= cm is less than orequal to c
These operators are used to compare numeric quantities (i.e., constants, numeric variables ornumeric expressions) or strings, thus forming
that are either
within a logical expression must be of the same type; i.e., both must be numericor both must be strings.In addition to the relational operators, Visual Basic contains several
. They are
(implies). The first three operators(
) are used to combine logical expressions, thus forming more complex logicalexpressions.
will result in a condition that is true if
expressions are true.
willresult in a condition that is true if
expression is true, or if they are both true;
,however, will result in a condition that is true
if one of the expressions is true and theother is false.
is used to reverse (
) the value of a logical expression (e.g., from trueto false, or false to true).
will result in a condition that is true if both expressions have the
logical value (either both true or both false); and
will always result in a truecondition unless the first expression is true and the second is false.
Information and Communication Technology DepartmentPalompon Institute of Technology
Relational Operators and Logical Expressions