• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

if vs elseif statements

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

What is more computationally expensive for WC3? Evaluating a string of if statements, or a string of a single if followed by elseif statements?

Suppose that the truth values of A, B, C are not related, but simply possible values that need to each have a check. In the case where A,B,C are not independent, then of course it makes sense to use elseif. But I am not referring to that case, therefore don't bring it up :p

JASS:
if A then
endif
if B then
endif
if C then
endif

JASS:
if A then
elseif B then
elseif C then
endif
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
won't compilewill compile
JASS:
if A then
endif
elseif B then
endif
elseif C then
endif

JASS:
if A then
elseif B then
elseif C then
endif
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
^ I know what he is asking, I just didn't know the answer. Why don't you dump the bytecode for us so we can at least make an educated guess?

Anyway, if that piece of code wasn't compiled then clearly it will be faster because wc3's engine will refuse to execute it, but that kind of answer is sarcastic.

EDIT:
I think IcemanBo's answer is the right one.
 
Last edited:
Level 15
Joined
Aug 7, 2013
Messages
1,338
Alright to put things in perspective I'm checking a series of button presses. I've been using if + elseif blocks, but I want to just use if…endif blocks for each button check so I can use a text macro to significantly reduce the number of lines from the programmer's point of view in order to ease editing. (yes I know it actually doesn't reduce the number of lines in the final compiled script).

I'm re-thinking now and I suppose I can use the type of block header as a parameter for the text macro.
 
Status
Not open for further replies.
Top