布尔运算

否定运算符 (!)

否定运算符(!),用来表示真假的反面的结果。如果运算值是 FALSE (0)结果为TRUE (1);如果运算不同于FALSE (0)等于FALSE (0)。

if(!a) Print("不是 'a'");

逻辑运算符或 OR (||)

x和y值的逻辑运算符或OR(||)用来表示两个表达式只要有一个成立即可。如果x和y值为真的,表达式值为TRUE (1)。否则,值为FALSE (0)。

if(x<0 || x>=max_bars) Print("超出范围");

逻辑运算符 AND (&&)

x和y值的逻辑运算符 AND (&&). 如果x和y值为真的(not null),表达式值为TRUE (1)。否则,值为FALSE (0)。

布尔运算的摘要评估

所谓的“摘要评估”模式是应用到布尔型操作系统中的, i.e.当表达式可以被精确的终止时,该表达计算就会停止。

//+------------------------------------------------------------------+

//| 脚本程序启动函数                                                   |

//+------------------------------------------------------------------+

void OnStart()

  {

//--- 简单判断的第一示例

   if(func_false() && func_true())

     {

      Print("Operation &&: You will never see this expression");

     }

   else

     {

      Print("Operation &&: Result of the first expression is false, so the second wasn't calculated");

     }

//--- 简单判断的第二示例

   if(!func_false() || !func_true())

     {

      Print("Operation ||: Result of the first expression is true, so the second wasn't calculated");

     }

   else

     {

      Print("Operation ||: You will never see this expression");

     }

  }

//+------------------------------------------------------------------+

//| 函数总是返回false                                                  |

//+------------------------------------------------------------------+

bool func_false()

  {

   Print("Function func_false()");

   return(false);

  }

//+------------------------------------------------------------------+

//| 函数总是返回 true                                                  |

//+------------------------------------------------------------------+

bool func_true()

  {

   Print("Function func_true()");

   return(true);

  }

另见

优先规则