Demystifying the Ternary Operator in AutoHotkey: Short-hand If-Else logic

TernAutoHotkey has pretty straight-forward If-Then-Else logic however it can take quite a few lines of code to do some simple evaluations.   Ternary Operators are a great way to write short / concise code in one line!  🙂

The basic form is that you first evaluate a condition.  If the value resolves to being true, the first parameter is returned.  If it is False, the second parameter is returned.

(Condition)?(True) : (False)


Ternary Operator video walk-throughAutoHotkey Merchandise-White Stress ball

;~ Ternary operator  
;~    (condition)?(True)    : (False)
data:= (var="3")?("is one"):("Not One")
MsgBox % data

data:= (Var="1")?("one")
MsgBox % data

data	:= (Var="1")?("one"):(Var="2")?("two"):(Var="3")?("three"):("Else") 
MsgBox % data

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.