# 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 in 0 : 100 r = x count += 1 assert r == 99 assert x == 100 assert count == 100 # with a step count = 0 for x as int in 0 : 100 : 2 r = x count += 1 assert r == 98 assert x == 100 assert count == 50 count = 0 for x as int in 1 : 100 : 2 r = x count += 1 assert r == 99 assert count == 50 # reverse order count = 0 for x in 100 : 0 : -1 r = x count += 1 assert r == 1 assert count == 100 # by 2 count = 0 for x as int in 100 : 0 : -2 r = x count += 1 assert r == 2 assert count == 50 # continue count = 0 for x in 1 : 10 r = x if x, continue # need conditional, some platforms err on dead code count += 1 assert r == 9 assert count == 0 # reverse, but no step specified count = 0 r = -1 for x in 10 : 2 r = x count += 1 assert count == 0 and r == -1 and x == 10 # reverse, but positive step specified count = 0 r = -1 for x in 10 : 0 : 2 r = x count += 1 assert count == 0 and r == -1 and x == 10 # one value implies start of 0 count = 0 for x in 10 r = x count += 1 assert count == 10 and r == 9 and x == 10 # using variables instead of constants i as int = 5 j as int = 10 count = 0 for x in i : j r = x count += 1 assert count == 5 and r == 9 and x == 10 # step it back i = 10 j = 5 stepp = -2 count = 0 for x in i : j : stepp r = x count += 1 assert count == 3 and r == 6 and x == 4 # the boundaries get evaluated once i = 5 j = 55 stepp = 2 count = 0 for x in i : j : stepp r = x count += 1 j = 10 stepp = 4 assert count == 25 and r == 53 and x == 55 # special test: node transformation inside a block if true count = 0 for x in 10 r = x count += 1 assert count == 10 and r == 9 and x == 10 Test().more def more i = 1 # reuse a local for i in 1 : 10 assert i assert i == 10 .foo(5) .bar def foo(x as int) assert x == 5 # reuse an arg: for x in 1 : 10 assert x assert x == 10 var _b as int def bar assert _b == 0 # reuse a class var: for _b in 1 : 10 assert _b assert _b == 10