Lotusscript的if语句会短路吗?

huangapple go评论106阅读模式
英文:

Does the Lotusscript if statement short circuit?

问题

快速回答:有人知道Lotusscript的if语句是否支持短路求值吗?文档中似乎没有提到这一点。

例如,如果doc.HasItem("MyField")的测试结果为false,则不会执行doc.MyField(0)=...的测试。

英文:

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 ...

答案1

得分: 2

在LotusScript中,if语句明确不支持短路。完整语句被评估,然后做出决定。有时这非常令人恼火,例如当您想执行以下操作时:

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

对于没有项 "SomeNumber" 的文档,这将引发 "类型不匹配" 错误,因为尽管第一个语句已经为false,但还是进行了比较...

英文:

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...

答案2

得分: 0

我不记得了。但试试看吧!

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

如果它没有打印出 "b",那么是的! 😊

英文:

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! 🙂

huangapple
  • 本文由 发表于 2023年7月31日 23:17:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804982.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定