How to iterate over pairs of table elements in lua? I would like to achieve a side-effect free way of circular and non-circular iterating ver pairs.
I have table like this:
t = {1,2,3,4}
Desired output of non-circular iteration:
(1,2)
(2,3)
(3,4)
Desired output of circular iteration:
(1,2)
(2,3)
(3,4)
(4,1)
Here’s the circular case
Non circular:
For fancier output use
print(string.format("(%d,%d)",x,y)