#.require. clr @platform clr # numeric for loops follow the half-open interval 0 .. N-1 which lines up with the zero indexing used in .NET for arrays, lists and strings. # see also Dijkstra's comments at http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF namespace Test class Test def main is shared r as int = 0 count as int = 0 # the usual for numeric: count = 0 for x as int = 0 .. 100 r = x count += 1 assert r==99 assert x==100 assert count==100 # with a ++ count = 0 for x as int = 0 .. 100 ++ 2 r = x count += 1 assert r==98 assert x==100 assert count==50 count = 0 for x as int = 1 .. 100 ++ 2 r = x count += 1 assert r==99 assert count==50 # reverse order count = 0 for x = 100 .. 0 -- 1 r = x count += 1 assert r==1, r assert count==100 # by 2 count = 0 for x = 100 .. 0 -- 2 r = x count += 1 assert r==2 assert count==50 # continue count = 0 for x = 1 .. 10 r = x continue count += 1 assert r == 9 assert count == 0 Test().more def more i = 1 # reuse a local for i = 1 .. 10 assert i assert i == 10 .foo(5) .bar def foo(x as int) assert x == 5 # reuse an arg: for x = 1 .. 10 assert x assert x == 10 var _b as int def bar assert _b == 0 # reuse a class var: for _b = 1 .. 10 assert _b assert _b == 10