|
Ralph1971 Wanderer
Joined: 01 Mar 2008 Posts: 64
|
Posted: Fri Feb 18, 2011 4:25 pm
#case vs #if |
Would it be better to do multiple nested #if's, or #case?
#if (@adept="yes") {#if (@dispel="yes") {cast dispel} {cast spell} {#if (@brew="yes") {brew spell} {#if (@scribe="yes") {scribe spell}} {cast spell}
I'm sure I've gotten lost with the closing brackets, but you get the point...
or..
#if (@adept="yes") {#case @dispelstatus {cast dispel} {cast spell}} {#case @spellstatus {Brew spell} {scribe spell}}
spellstatus previously given a value of 1, 2, 3 etc earlier |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Feb 18, 2011 5:46 pm |
in the case of a binary evaluation (ie, true/false), it doesn't matter. The coding advantage of #CASE versus #IF only comes into play when you have 3 or more outcomes from a single condition:
1)#CASE only evaluates the condition once
Code: |
#variable count 4
#CASE @count {} {} {} {} |
2)nested #IFs evaluate at least 3 times (given the example above)
Code: |
#variable count 4
#IF (@count = 4) {
} {
#if (@count = 3) {
} {
#if (@count = 2) {
} {
}
} |
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|