03-14-2022, 09:21 AM
(03-14-2022, 08:50 AM)boriel Wrote: I repeat: The FIRST variant is OK, compiles OK, and runs Ok.
What do you mean by "confused the compiler"? (i.e. syntax error?)
Also, the second variant is ok, but you're mixing block IF sentences with single-line IF sentences and is confusing. You can write it as:
Code:IF X = 1 THEN
X = 2
ELSEIF X = 2 THEN
IF T < 10 THEN X = 3
END IF
Which looks clearer.
ELSEIF is like SWITCH in other languages like C/C++. Once a condition is fulfilled, the remaining ones are skipped which leads to faster execution.
Hi Boriel,
Sorry, I don’t think it’s a case that the compiler is wrong but mixing multi-line and in-line IFs causes the unexpected results (or was it a failure to compile? I can’t remember now). Maybe it was not enough or too many END IFs? I don’t think you have anything to worry about here.
Thanks for explaining the advantage of ELSEIF. I’ll look forward to refactoring my code and hopefully get a tangible speed boost!
Steve
Follow my game’s progress here
https://spectrumcomputing.co.uk/forums/v...php?t=6541
https://spectrumcomputing.co.uk/forums/v...php?t=6541