Feature request > IDE/Syntax
AndAlso
spicypixel:
--- Quote from: Ocean on 2012-Jan-08 ---what's wrong with:
--- Code: ---IF ( Check1(x1) AND Check1(x2) AND Check1(x3) AND x1 > 0 AND x1 <=10 ) THEN Blah=0
--- End code ---
?
cheers
Ocean
--- End quote ---
I was gonna post whats wrong with using AND but thought I must have stupidly missed something :D
Ruidesco:
What Bigsofty means is that using ANDs the whole chain of equations has to be evaluated no matter their individual results, while with ANDALSOs the chain evaluation is aborted when one of the equations turns to be false, thus saving some process time; that is why the concatenation of ANDALSOs works like nestled IFs, but is cleaner when it comes to code formatting.
bigsofty:
The problem with AND is that it's a logical operator, there may an occasion that using a logic calculation is required, part of an algorithm for example(even within an IF). As such the compiler does not always know what or when to cut out.
AndAlso is not the same as AND it more closely to nested IFs, one way that may operate GLB in a similar manner is...
IF a=b THEN IF c=d THEN IF e=f THEN x=0
Although that's a bit messy and I'm not sure it would work.
It's quite a popular command, used in VB,C#, Freebasic etc... Here's the VB manual entry for it for example, http://msdn.microsoft.com/en-us/library/cb8x3kfz(v=vs.80).aspx
Kitty Hello:
Nohoooo!
See this examle:
--- Code: ---
DEBUG "with AND\n"
IF ok() AND ok() THEN PRINT 0,0,0
DEBUG "now with OR\n"
IF ok() OR ok() THEN PRINT 0,0,0
DEBUG "not ok with AND\n"
IF notok() AND ok() THEN PRINT 0,0,0
FUNCTION ok:
DEBUG "Call to ok()\n"
RETURN TRUE
ENDFUNCTION
FUNCTION notok:
DEBUG "Call to notok()\n"
RETURN FALSE
ENDFUNCTION
--- End code ---
you will notice, there's only one call to "ok()" for the OR operator, because if the first condition is true, the 2nd condition does not matter anymore and won't be evaluated.
Same for the last line, where "notok()" already returns false and the ok() won't be called.
AND and OR are evaluated left to right.
kanonet:
Thanks Kitty, didnt know that, now i can reorganise some code.
Could you plz, mention that in the help file, cuz its an nice feature, but not the expected behaviour.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version