Re: for loop with more items

2018-08-17 Thread RWS
Thx you all. I' was trying to find a way to make the same of this C# code with a similar syntax: for (int x = 0, y = 0; x <= 10 && y <= 10; x++, y++) { Console.WriteLine(x + y); } but i got lost on the way

Re: for loop with more items

2018-08-17 Thread kaushalmodi
The a, b are not actually start/end values. They are arbitrary elements from the first and second slices (r[0] and r[1]).

Re: for loop with more items

2018-08-17 Thread mratsim
Maybe Slice should use (slice_start, slice_end) for naming instead of (a, b).

Re: for loop with more items

2018-08-16 Thread kaushalmodi
But this is Nim, you can do Anything (TM) :D iterator pairs(r: array[0 .. 1, HSlice[system.int, system.int]]): tuple[a: int, b: int] = for r1 in r[0]: for r2 in r[1]: yield (r1, r2) for x, y in [0 .. 3, 0 .. 3]: echo x, " ", y Run

Re: for loop with more items

2018-08-16 Thread kaushalmodi
This will help you understand that code better: import strformat, typetraits let r = [0 .. 3, 0 .. 3] echo fmt"r = {r}, of type `{$r.type}'" for x, y in r: echo fmt"x = {x}, of type `{$x.type}'" echo fmt"y = {y}, of type `{$y.type}'" Run Ou

Re: for loop with more items

2018-08-16 Thread emekoi
the for loop is iterating over the array and not the ranges in the array. afaik you can't iterate over two ranges like that in nim.

for loop with more items

2018-08-16 Thread RWS
Hi there. I'm doing some experiments with Nim. Can anyone explain how this code: for x, y in [0..10, 0..10]: echo(x) echo(y) Run gives this output: 0 (a: 0, b: 10) 1 (a: 0, b: 10) and is there a way to work this 2 or more items in a for loop? Thx