Does the Lotusscript if statement short circuit?

63 Views Asked by At

Quick one: Does anyone know if the Lotusscript if statement short circuits? Nothing appears to be written in the documentation.

E.g. if doc.HasItem("MyField") test is false, the doc.MyField(0)=... test is not performed.

if doc.HasItem("MyField") and doc.MyField(0)<>"" then ...
2

There are 2 best solutions below

0
Tode On BEST ANSWER

The if statement in LotusScript definitvely doesn't short circuit. The complete statement is evaluated and then the decision is made. This sometimes is very annoying e.g when you want to do something like:

If doc.HasItem( "SomeNumber" ) and doc.GetItemValue( "SomeNumber" )(0) > 100 Then

This will throw a "Type mismatch" for documents that do not have the item "SomeNumber" as the comparision is made although the first statement is already false...

1
JSmart523 On

I don't remember. But try it out!

Function p(x As String) as Boolean
  print x
  p = True
End Function

Sub test()
  If p("a") or p("b") Then
    p("c")
  End If
End Sub

If it doesn't print "b" then yes!