Code: Select all
array := ["a", "b", "c", "d", "e"]
object := {a:1,b:2,c:3,d:4,e:5}
s := ""
for k,v in Range(array, 2, 4) ; Integers 2 to 4
s .= k "=" v "`n"
s .= "`n"
for k,v in Range(object, "", "c") ; Strings up to "c"
s .= k "=" v "`n"
MsgBox % s
class EnumRange {
__new(obj, min, max) {
this.obj := obj
this.min := min
this.max := max
}
_NewEnum() {
if this.enm {
; ... code to clone and reset goes here ...
}
return this
}
Next(ByRef a, ByRef b) {
if !this.enm {
this.enm := ObjNewEnum(this.obj)
loop
r := this.enm.Next(a, b)
until !r || a >= this.min
}
else
r := this.enm.Next(a, b)
return r && a <= this.max
}
}
Range(obj, min, max) { ; Optional function for readability.
return new EnumRange(obj, min, max)
}