Sounds like a keyword my av-ee-tar would like. ELSEIF ya don't, I'm eh gonna blast youse.
Okay, settle down Yosemite, and let's have a look at this handy conditional statement.
SYNTAX:
IF foo1 THEN
ELSEIF foo2 THEN
END IF
Usage: Handles multiple conditions while excluding program flow through unnecessary evaluation statements.
This is a nice alternative to SELECT CASE, and better than forcing your program through multiple IF/THEN statements, which could cause more than one desired condition to be triggered.
Example:
So by using IF THEN with ELSEIF in a block statement we get an output of '1' and done in the first condition block vs all three numbers printed out in the second IF/THEN only block.
--------------------------------------------------------------------------------------
Edit: Oh, here's a fun coding fact, inspired by mn's post below....
We can code a regular IF/THEN non-block statement with THEN (line number)...
...but with an IF/THEN/ESLEIF, the THEN part cannot reference a line number without using GOTO with it.:
Pete
Okay, settle down Yosemite, and let's have a look at this handy conditional statement.
SYNTAX:
IF foo1 THEN
ELSEIF foo2 THEN
END IF
Usage: Handles multiple conditions while excluding program flow through unnecessary evaluation statements.
This is a nice alternative to SELECT CASE, and better than forcing your program through multiple IF/THEN statements, which could cause more than one desired condition to be triggered.
Example:
Code: (Select All)
a = 1: b = 2
IF a > b OR j = 0 THEN
PRINT "1"
ELSEIF a = b OR j = 0 THEN PRINT "2"
ELSEIF a < b OR j = 0 THEN PRINT "3"
END IF
PRINT "---------------------------------"
IF a > b OR j = 0 THEN PRINT "1"
IF a = b OR j = 0 THEN PRINT "2"
IF a < b OR j = 0 THEN PRINT "3"
So by using IF THEN with ELSEIF in a block statement we get an output of '1' and done in the first condition block vs all three numbers printed out in the second IF/THEN only block.
--------------------------------------------------------------------------------------
Edit: Oh, here's a fun coding fact, inspired by mn's post below....
We can code a regular IF/THEN non-block statement with THEN (line number)...
...but with an IF/THEN/ESLEIF, the THEN part cannot reference a line number without using GOTO with it.:
Code: (Select All)
IF a = b THEN 5 ' This is accepted.
PRINT "Skip me!"
5 PRINT "Okay, I skipped you!"
IF a = b THEN
PRINT "Okay!"
ELSEIF a < b THEN GOTO 5 ' You have to include GOTO here or it won't compile.
END IF
Pete