« Return to Thread: comma vs andalso

Re: comma vs andalso

by Richard Carlsson-2 :: Rate this Message:

Reply to Author | View in Thread

Roberto Ostinelli wrote:
> the difference is very simple. comma indicates that both guard operators
> need to be evaluated, while on the contrary 'andalso' means that the
> second condition is evaluated ONLY if condition1 is true. same goes for
> 'orselse'.

No, the comma separator in guards also uses short-cut evaluation
and will not evaluate the subsequent tests if one test fails. If
there are alternatives expressed with semicolon, the next such
alternative will be tried instead; otherwise, the whole guard fails.

What you describe is true for the 'and' operator compared to 'andalso'.

    /Richard

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

 « Return to Thread: comma vs andalso