So I'm just posting this in case anyone has anything interesting to say on the topic, or has some good links re. this issue. Cheers.
Code: Select all
;q:: ;objects - loop and delete - delete all (undesirable results)
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
vOutput := ""
Loop, % oArray.Length()
{
vOutput .= oArray[A_Index]
oArray.RemoveAt(A_Index)
}
MsgBox, % vOutput " " StrLen(vOutput) ;acegikmoqsuwy 13
MsgBox, % oArray.Length()
oArray := ""
return
;w:: ;objects - loop and delete - delete all
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
vOutput := ""
Loop, % oArray.Length()
{
vOutput .= oArray[1]
oArray.RemoveAt(1)
}
MsgBox, % vOutput " " StrLen(vOutput) ;abcdefghijklmnopqrstuvwxyz 26
MsgBox, % oArray.Length()
oArray := ""
return
;==================================================
;q:: ;objects - loop and delete - forwards loop
Loop, 2
{
vKeepVowels := (A_Index = 1)
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
vIndex := 0
Loop
{
vIndex++
if !oArray.HasKey(vIndex)
break
vValue := oArray[vIndex]
if vKeepVowels && !RegExMatch(vValue, "[aeiou]")
oArray.RemoveAt(vIndex), vIndex -= 1
if !vKeepVowels && RegExMatch(vValue, "[aeiou]")
oArray.RemoveAt(vIndex), vIndex -= 1
}
vOutput := ""
Loop, % oArray.Length()
vOutput .= oArray[A_Index]
MsgBox, % vOutput " " StrLen(vOutput)
}
return
;==================================================
;q:: ;objects - loop and delete - backwards loop
Loop, 2
{
vKeepVowels := (A_Index = 1)
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
Loop, % vCount := oArray.Length()
{
vIndex := vCount+1-A_Index
if !oArray.HasKey(vIndex)
break
vValue := oArray[vIndex]
if vKeepVowels && !RegExMatch(vValue, "[aeiou]")
oArray.RemoveAt(vIndex)
if !vKeepVowels && RegExMatch(vValue, "[aeiou]")
oArray.RemoveAt(vIndex)
}
vOutput := ""
Loop, % oArray.Length()
vOutput .= oArray[A_Index]
MsgBox, % vOutput " " StrLen(vOutput)
}
oArray := ""
return
;==================================================
;q:: ;objects - loop and delete - for loop (undesirable results)
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
for vKey, vValue in oArray
oArray.RemoveAt(vKey)
vOutput := ""
for vKey, vValue in oArray
vOutput .= oArray[A_Index]
MsgBox, % vOutput " " StrLen(vOutput) ;bdfhjlnprtvxz 13
return
;w:: ;objects - loop and delete - for loop (undesirable results)
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
for vKey, vValue in oArray
oArray.Delete(vKey)
vOutput := ""
for vKey, vValue in oArray
vOutput .= oArray[A_Index]
MsgBox, % vOutput " " StrLen(vOutput) ;bdfhjl 6
return
;==================================================
;q:: ;objects - loop and push to new array - for loop
Loop, 2
{
vKeepVowels := (A_Index = 1)
oArray := StrSplit("abcdefghijklmnopqrstuvwxyz")
oArray2 := []
for vKey, vValue in oArray
{
if vKeepVowels && RegExMatch(vValue, "[aeiou]")
oArray2.Push(vValue)
if !vKeepVowels && !RegExMatch(vValue, "[aeiou]")
oArray2.Push(vValue)
}
vOutput := ""
Loop, % oArray2.Length()
vOutput .= oArray2[A_Index]
MsgBox, % vOutput " " StrLen(vOutput)
}
oArray := oArray2 := ""
return
;==================================================
;q:: ;objects - potentially infinite loop - for loop
oArray := ["a"]
for vKey, vValue in oArray
{
if (A_Index = 1000)
break
oArray.Push("x")
}
MsgBox, % oArray.Length()
return