AutoHotkey 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.
One-Line Operators in AutoHotkey are a great way to streamline / condense your code! In the below video I walks through how to use them. While I use them in a loop, this was merely an easy way to demonstrate them.
One-Line Operators in AutoHotkey Video Tutorial
Example AutoHotkey code of One-Line Operators in AutoHotkey
Loop, parse, Var, `n, `r ;loop over Var line by line
myVar:=A_Index ;increment myVar
IfEqual, A_Index,1,continue ;skip processing header/1st row
IfEqual, A_LoopField,,continue ;Skip loop if A_Loopfiled is blank
IfEqual, A_Index,3,SetEnv,Data,New Value ;If A_Index is 3 set data:="New Value"
IfEqual, A_Index,5, Sleep, 2000 ;Sleep for 2 seconds on 3
IfEqual, myVar,6,EnvAdd,myVar, 2 ;If myVar=6 add 2 to myVar
IfEqual, A_LoopField,three,break ;Note- need to use percents if variable
IfEqual, A_index, 4, ExitApp ;Exit app if get to 10
IfLess, A_Index,6,FileAppend,%A_Loopfield%`r`n,test.txt,utf-8 ;If A_Index <6, write A_loopfield to test.txt
MsgBox % "index: " A_Index A_Enter "LoopField: " A_LoopField A_Enter "Data: " Data A_Enter "myVar: " myVar