Re: Short form of "if" statement
- Posted by DerekParnell (admin) Dec 26, 2012
- 1103 views
SnakeCharmer said...
Offer to include "then" keyword for "if" with only consequence and without "else" branch. Example:
if x < 0 then x = -x
instead of
if x < 0 x = -x end if
I think, it would be very useful.
Note that 'then' is required for the 'if' statement, so your second code example should be ...
if x < 0 then x = -x end if
Also note that you do not have to use multiple lines when using the 'if - then - end if' form. eg...
if x < 0 then x = -x end if
Which is very close to what your suggestion was about.
The reason that the syntax requires 'then', and 'end if' is to allow multiple statements to exist in an 'if' statement and to not rely on text (line) formatting as a syntax requirement.