Conditionally chooses one of two responses based on the result of an expression.
(expression) ? (expression1 if expression is True) : (expression2 if expression is False)
expression | If the expression is true, the expression1 is executed - if false, the expression2 is executed |
This Conditional operator allows a binary choice to be executed without the overhead of an If...Else...EndIf structure.
Although not necessary in all cases, it is strongly recommended that the 3 elements are enclosed in parentheses.
If...Else...EndIf, Select...Case...EndSelect, Switch...EndSwitch
#include <MsgBoxConstants.au3>
Example()
Func Example()
; The values are the same so the expression is True
MsgBox($MB_SYSTEMMODAL, "Result: 1=1", (1 = 1) ? "True!" : "False!")
; The values are not the same so the expression is False
MsgBox($MB_SYSTEMMODAL, "Result: 1=2", (1 = 2) ? "True!" : "False!")
EndFunc ;==>Example