CSET 3250
Conditional Statements

Introduction

Conditional statements are used to make decisions and perform different actions depending on the decision.

Conditonal statements

The different conditional statements are as follows.

If-Then-Else
The If...Then...Else statement is used to evaluate whether a condition is True or False and, depending on the result, specifies one or more statements to run.
If you want to execute only one statement when a condition is true, you can write the code on one line.

If  i = 10 then msgbox " Stock is 1200"
To perform multiple actions when a condition is true, you must put each statement on separate lines and end the statement with the keyword "End If":
If i =10 then
msgbox"Stock is 1200"
i = i +10
end if
The "Else" keyword is used when you want to perform one action if the statement is true and another when it is false.
If i =10 then
msgbox"Stock is 1200"
else
msgbox" More required"
end if

If-then-Elseif
If...then...elseif statement is used when you want to select one of many blocks of code to execute:

If value = 0 Then
MsgBox value 
ElseIf value = 1 Then
MsgBox value
ElseIf value = 2 then
Msgbox value
Else 
Msgbox "Value out of range!" 

Select Case
Select Case statement provides capability similar to the If...Then...Else statement.
A Select Case structure works with a single test expression that is evaluated once. The result of the expression is then compared with the values for each Case in the structure. If there is a match, the block of statements associated with that Case is executed,

Select case value
case "1"
msgbox "Less than zero"
case "2"
msgbox "Greater than zero"
case "3"
msgbox "Equals zero"
case else
msgbox"Value unknown"
end select

 

There have been visitors since 11/26/2003

Added to the Web: May 26, 2000.

Web page design by Dan Solarek.

http://cset.sp.utoledo.edu/cset3250/