Discussions related to Visual Prolog
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Optional then in an if/then/else statement

Unread post 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?
Mutall Data Management Technical Support
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post 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.
Regards Thomas Linder Puls
PDC
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez »

I agree with the "awkward"

Stay consistent with the then as always part of the syntax.
AI Rules!
P.
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Unread post 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:-

Code: Select all

... if condition() end if, ...
is equivalent to simply

Code: Select all

... condition(), ...
Mutall Data Management Technical Support
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post 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
Peter Muraya
VIP Member
Posts: 147
Joined: 5 Dec 2012 7:29

Unread post 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

Code: Select all

if
in the multi-line version.
Mutall Data Management Technical Support
Post Reply