[Closed] do vs then?
I’ve been told by a couple of very experienced maxscripters to not use “do” when you can use “then”
Only reason that I can remember is they said if you decide later that you need an “else”, you need to change the “do” to a “then”. But that doesn’t seem like such a big deal.
Is “then” better than “do” for other reasons? Why?
Cheers,
Cg.
i always use DO if it’s not followed by ELSE.
for it’s easier to see when a condition has alternative or not… it might be a pretty long code block, but if i see DO it means there’s not ELSE after. But if i see THEN it means it’s followed by ELSE.
there is no really advantage or disadvantage of using DO vs THEN but…
if you copy a code from a script to clipboard like:
if true the print true
and will try to execute it in the listener, it will stop waiting for ELSE.
the expression:
if true do print true
will be executed without a problem.
this is another reason for me to use DO where it doesn’t need ELSE
Thanks Denis. I’m of the same opinion and have scripted for years with “do” unless I needed an “else” but have lately started moving over to the “then” way ’cause of advice. But then I thought hang on, I’d better check to see if there’s valid reasons to do so. I resisted switching from “do” to “then” for so long cause I’m sure Bobo uses “do” a lot.
Back to “do” it is then.
Cheers,
Cg.
I don’t know how this is treated by the compiler internally, but in the listener, you’ll get a hanging/incomplete statement In the case of “then” without “else” following. You can only break that by hitting escape.
I seem to remember one of the devs stating that there is a slight performance gain when using “do” in that case, possibly because there might be an exception involved internally in the other case, but can’t remember exactly. Running some quick tests using “if…then” vs “if…do” in a loop did’nt show anything special performance related …
this is a MYTH. There is no any difference in performance or memory usage (at least in versions before 2017) for using DO vs THEN