I am looking to traverse a NxN area, given the starting points X,Y and the size of the square to traverse. E.g. given X=10,Y=12,Size=2 - i want to generate 10,10 ; 10,11 ; 11,10 and 11,11.
I came up with this, but it seems to go on and on infinitely:
traverse({X,Y,Xend,Yend}) ->
% print X,Y values here....
case (X == Xend-1) andalso (Y == Yend-1) of
true ->
ok;
_->
case (Y < Yend-1) of
true ->
traverse({X,Y+1,Xend,Yend});
_->
traverse({X+1,Y,Xend,Yend})
end
end.
I called the above function from another function using:
Size = 3,
traverse({10,20,10+Size,20+Size}).
What am I doing wrong? I am actually new to the functional paradigm, and I tried implementing this on C, using "return" in the place of "ok" above, and it worked, but I am guessing, i'm not thinking "functionally" enough!