When do I use If...Then and when If...Do?

MAXScript FAQ > When do I use If...Then and when If...Do?

Generally, you can use both If...Then and If...Do within script code, but you cannot use If...Do when an 'else' expression is required for the cases the condition evaluates to false.

One of the reasons If...Do exists is to make typing in the Listener easier.

When you enter

if a==0 then print "A is Zero!"

the MAXScript Listener assumes that an 'else' expression will follow because you used 'then'.

So it will sit around waiting for you to enter the 'else' expression, and will seem to hang.

(Note that you can use the Escape key to interrupt the Listener and exit from this "hanging" mode).

If you have no intentions to enter a second expression after an 'else', you should type in

if a==0 do print "A is Zero!"

The Listener will notice you used 'do' and therefore don't want to enter an 'else' expression and will execute the line immediately!

For more details, see If Expression

See Also