Hi Robert
The following examples test a numeric variable and displays a message
with a word in it:
A hypothetical SELECT CASE... ENDCASE structure may look like this:
(There are variations between different languages and dialects)
Code: Select all
SELECT CASE
CASE vResult =1 ` Test if the number is 1
PRINT "One." ` If it is 1, display a message
CASE vResult = 2 ` Test if the number is 2
PRINT "Two." ` If it is 2, display a message
CASE vResult = 3 ` Test if the number is 3
PRINT "Three." ` If it is 3, display a message
OTHERWISE ` If it is not 1, 2, or 3, display a message
PRINT "It was not one, two, or three."
ENDCASE
For comparison, here is a IF THEN...ELSE...ENDIF version in Control Basic
of the same method:
Code: Select all
IF vResult = 1 THEN ' Testst if the number is 1
PRINT "One." 'If it is 1, display a message
ELSE
IF vResult = 2 THEN ' Test if the number is 2
PRINT "Two." ' If it is 2, display a message
ELSE
IF vResult = 3 THEN ' Test if the number is 3
PRINT "Three." ' display a message
ELSE ' If it is not 1, 2, or 3, display a message
PRINT "It was not one, two, or three."
ENDIF
ENDIF
ENDIF
Downsides of the IF THEN...ELSE...ENDIF structure are that it is not as intuitive and it does not look
as elegant as the SELECT CASE... ENDCASE structure.
Remember that with a SELECT CASE...OTHERWISE...ENDCASE method, only the first TRUE
case is executed. Even if two or more cases are TRUE, only the statements
following the first TRUE case will be executed.
In the IF THEN...ELSE...ENDIF method, each case is evaluated in succession.
One or more cases can be TRUE
Hope this helps
Best regards
Andries