Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v2) • Re: Simple logic question... Best way for "for else" setup?

$
0
0
If I understand what you are asking... my preference would be a dedicated function...
Might even be worth adding a custom method for array

CODE:

a := ['a','b','c','d','e','f']
MsgBox hasVal(&a,'e')
hasVal(&arr, val, casesense:=0) {
if (!IsObject(arr))
return 0
for idx, item in arr {
if (!IsSet(item))
continue
else if (item == val)
return idx
else if (item = val && !casesense)
return idx
}
return 0
}


or thru prototyping (viewtopic.php?t=124270)

CODE:

Array.Prototype.DefineProp("hasVal", {Call:array_hasVal})
a := ['a','b','c','d','e','f']
MsgBox a.hasVal('e')
array_hasVal(arr, val, casesense:=0) {
for idx, item in arr {
if (!IsSet(item))
continue
else if (item == val)
return idx
else if (item = val && !casesense)
return idx
}
return 0
}

Statistics: Posted by andymbody — Today, 16:39



Viewing all articles
Browse latest Browse all 579

Trending Articles