• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

if vs elseif statements

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
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,337
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