5.times do puts 'x' end x x x x x (0..21).step(3) do |i| puts i end 0 3 6 9 12 15 18 21
Problem is, that from my current understanding iterators in Nim are coupled to for statement and a counting variable, so that a plain times iterator seems not doable. And, I still do not know how to pass more parameters to iterators to have a step size for example.
for i in 1..5: echo "x"
for i in countUp(0,21,3): echo i
Generally I would recomment to just write for i in 1..5: echo 'x', but if you really want that syntax:
template times(x: expr, y: stmt): stmt =
for i in 1..x:
y
5.times:
echo 'x'