Operator Reference


Ternary

Conditionally chooses one of two responses based on the result of an expression.

(expression) ? (expression1 if expression is True) : (expression2 if expression is False)

Parameters

expression If the expression is true, the expression1 is executed - if false, the expression2 is executed

Remarks

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.

Related

If...Else...EndIf, Select...Case...EndSelect, Switch...EndSwitch

Example

#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