If statement 在单行If-语句中执行两个命令

If statement 在单行If-语句中执行两个命令,if-statement,autoit,If Statement,Autoit,我想在一行If-语句中执行两个命令: 虽然下面的代码段运行时没有错误,但变量$F_Akr_Completed未设置为1,但MsgBox()正确显示(带有“F为0”) 你知道为什么它不起作用时没有报告语法错误吗?没有错误,因为 If x = x Then x And x 是有效语句,x和x是逻辑表达式。有很多方法可以做到这一点,例如: If Not ($F_Akr_Completed And ProcessExists($PID_Chi)) Then $F_Akr_Completed = 1 +

我想在一行
If
-语句中执行两个命令:

虽然下面的代码段运行时没有错误,但变量
$F_Akr_Completed
未设置为
1
,但
MsgBox()
正确显示(带有“F为0”)


你知道为什么它不起作用时没有报告语法错误吗?

没有错误,因为

If x = x Then x And x
是有效语句,
x和x
是逻辑表达式。有很多方法可以做到这一点,例如:

If Not ($F_Akr_Completed And ProcessExists($PID_Chi)) Then $F_Akr_Completed = 1 + 0 * MsgBox(1,1,"[Info]    Akron parser completed. F is " & 1)
但这是一种糟糕的编码风格。AutoIt是一种非常冗长的语言,我建议将多个语句分开

也可以使用三元运算符指定值:

$F_Akr_Completed = (Not ($F_Akr_Completed And ProcessExists($PID_Chi))) ? 1 : 0
这和

$F_Akr_Completed = Int(Not ($F_Akr_Completed And ProcessExists($PID_Chi)))
$F_Akr_Completed = Int(Not ($F_Akr_Completed And ProcessExists($PID_Chi)))