Demystifying the Ternary operator
Code: Select all
Browser_Forward::Reload
Browser_Back::
var:="2"
;~ Ternary operator
;~ (condition)?(True) : (False)
data:= (var="3")?("is one"):("Not One")
MsgBox % data
data:= (Var="1")?("one")
:(Var="2")?("two")
:(Var="3")?("three")
:("Else")
MsgBox % data
data := (Var="1")?("one"):(Var="2")?("two"):(Var="3")?("three"):("Else")
MsgBox % data
One line logic in AHK
Code: Select all
A_enter:="`r`n"
Browser_Back::
my:="hello"
var=
(
one
two
three
five
six
seven
)
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
IfEqual, A_Index,4,ListVars
MsgBox % "index: " A_Index A_Enter "LoopField: " A_LoopField A_Enter "Data: " Data A_Enter "myVar: " myVar
}