fb:porticula NoPaste
Beispiel für Iteratoren-Überladung
Uploader: | nemored |
Datum/Zeit: | 03.07.2010 21:40:07 |
'Fehlt noch was, um FOR ohne STEP zu ermöglichen
'
type typ
as integer a, b
declare operator for
declare operator for(stp as typ)
declare operator step
declare operator step(stp as typ)
declare operator next(dat as typ) as integer
declare operator next(dat as typ, stp as typ) as integer
end type
operator typ.for
end operator
operator typ.for(stp as typ)
end operator
operator typ.step
this.a += 1
this.b += 1
end operator
operator typ.step(stp as typ)
this.a += stp.a
this.b += stp.b
end operator
operator typ.next(dat as typ) as integer
if this.a > dat.a then return 0
if this.b > dat.b then return 0
return -1
end operator
operator typ.next(dat as typ, stp as typ) as integer
if (stp.a >= 0 and this.a > dat.a) or (stp.a <= 0 and this.a < dat.a) then return 0
if (stp.b >= 0 and this.b > dat.b) or (stp.b <= 0 and this.b < dat.b) then return 0
return -1
end operator
dim as typ i, start, ende, schritt
start = type<typ>(5,3)
ende = type<typ>(9, 0)
schritt = type(2, -1)
for i = start to ende step schritt
print i.a, i.b
next