- Joined
- Nov 30, 2007
- Messages
- 1,202
I try to condense my code by using loops, but some times that requires a few additional setup functions this has caused me to reach the OP limit and now I'm at a loss having spent so much time trying to device complicated ways for the code to work.
Lets take an example:
This is the simplest example, they both have 3 conditions depending on something that can be indexed writing the latter one is faster, if you exclude he time it takes to arrange the index for the conditions. It's usually less overall code, however it has additional lines which execute because it's inside a loop. This scenario is obviously irrelevant but I use it to illustrate that maybe those 100's of lines for if-statements are not so bad after all?
Also note usually it's not as clear cut, some time you add additional if's and set the integers in some elaborate way making the overhead much bigger than this example.
=====
So my question I suppose, am I wrong to try to write shorter code and straying away from line upon line of if-statements if i'm doing the same thing in the end and more?
Lets take an example:
JASS:
if A then
//Similar code block
elseif B then
//Similar code block
elseif C then
//Similar code block
endif
// vs
local integer i = 0
loop
if A[i] then
// Similar Code block
endif
set i = i + 1
exitwhen i == 3
endloop
Also note usually it's not as clear cut, some time you add additional if's and set the integers in some elaborate way making the overhead much bigger than this example.
=====
So my question I suppose, am I wrong to try to write shorter code and straying away from line upon line of if-statements if i'm doing the same thing in the end and more?