为什么有四个逻辑运算符:
&, &&
|, ||
使用上有什么区别?
是的,我查看了文档,但还是有点困惑。文档上说:
‘&’ and ‘&&’ indicate logical AND and ‘|’ and ‘||’ indicate
logical OR. The shorter form performs elementwise comparisons in
much the same way as arithmetic operators. The longer form
evaluates left to right examining only the first element of each
vector. Evaluation proceeds only until the result is determined.
The longer form is appropriate for programming control-flow and
typically preferred in ‘if’ clauses.
我认为一个例子会清晰地展示它们。谢谢。