Page 1 of 1
Optional then in an if/then/else statement
Posted: 22 Sep 2015 9:08
by Peter Muraya
Thomas,
I'm thinking about this code that does nothing on
then:-
Code: Select all
if condition() then else do_something() end if
Suppose you do away with
then, so that:-
Code: Select all
if condition() else do_something() end if
is recognized as a valid statement. What are your thoughts on this?
Posted: 22 Sep 2015 10:37
by Thomas Linder Puls
This has already been discussed internally and the conclusion was that too many people found it awkward.
But I can take it up again.
Posted: 22 Sep 2015 11:05
by Paul Cerkez
I agree with the "awkward"
Stay consistent with the then as always part of the syntax.
Posted: 22 Sep 2015 17:14
by Peter Muraya
... and if both
then and
else are omitted, then the compiler ignores the
if/end if and executes the condition, so that:-
is equivalent to simply
Posted: 22 Sep 2015 20:30
by Harrison Pratt
On the scale of things we need to manage, this is a tiny one However, Microsoft has made
then optional for multi-line statements, at least in VB.
https://msdn.microsoft.com/en-us/library/752y8abs.aspx
Posted: 23 Sep 2015 5:48
by Peter Muraya
Thank you Harrison for the link.
VB has the notion of a multi-line syntax which Prolog does not (except for comments where % is for single line and /**/ is for mult-line) . So, the empty
if statement can is coded in 2 different ways in VB:-
Code: Select all
' Multiple-line syntax:
If condition
End If
and
Code: Select all
' Single-line syntax:
If condition Then
Note that (a) the single line syntax has no
end if and (b)
end if must appear on a different line from the
in the multi-line version.