When to prefer `and` over `andalso` in guard tests

前端 未结 4 839
别那么骄傲
别那么骄傲 2021-02-02 08:48

I am curious why the comma ‹,› is a shortcut for and and not andalso in guard tests.

Since I\'d call myself a “C native” I fail to see any shor

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 09:31

    The boolean operators "and" and "or" always evaluate arguements on both the sides of the operator. Whereas if you want the functionality of C operators && and || (where 2nd arguement is evaluated only if needed..for eg if we want to evalue "true orelse false" as soon as true is found to be the first arguement, the second arguement will not be evaluated which is not the case had "or" been used ) go for "andalso" and "orelse".

提交回复
热议问题