There is a piece of C code
int i, j = 0;
for (i = 0, j = n-1; i < n; j = i++) {
// array operations
}
that I’m trying to convert into Lua code
local j = n-1
for i = 1, n do -- arrays are 1-based in Lua
-- array operations
j = i+1
end
but for some reason Lua code doesn’t work. Am I getting that C loop right?
Imagine an array as a circular buffer.
iis the current item andjis always the previous one:Demo: