Hi!
What's the best way to emulate the C/C++ for loop using a template or macro in Nim?
For example:
forc var i = 1, i <= 10, i += 1:
echo i
I've made several tests but it does not work, like:
template forc(init, comp, incr, body: untyped) =
block:
init
while comp:
body
incr
Thanks
You were quite close:
template forc(init, comp, incr, body: untyped) =
block:
init
while comp:
body
incr
forc((var i = 1), i <= 10, inc i):
echo i
Edit: Removed useless {.immediate.}Of course we have already countup and countdown iterators:
let a = 2
for i in countup(a, a + 12, a + 1):
echo i
I wondered what the immediate pragma does. According to the docs the immeridate pragma is not needed and will be deprecated later.