[SOLVED] I'm confused, Is a bug of 'repeat until'?
Posted: Fri Dec 01, 2023 12:04 am
I have never had this problem
the code is right, isn't it?
but it alwalys runs that
first
whatever I change the code to prevent it happening
If conditions are satisfied, however i change it and its place, 'repeat until' always runs these bananas code first, and then it causes error, which says attempt to index nil value in o:func, because the values in bananas had been assigned nil
when I use 'for' with bananas[ii] = nil
everything is right!?
values in bananas are not nil in o:func
for logic reason i must use repeat until, or alternative 'goto', well goto has been tested, it also has this problem --test file here
Code: Select all
local queue = {}
local bananas = {}
function love.run()
-- ***
-- above are same as love.run
local i = 1
repeat
if queue[i] then
for _, o in pairs(queue[i]) do
o:func(bananas[i])
end
bananas[i] = nil
end
i = i + 1
until(i > 5)
-- below are same as love.run
-- ***
end
but it alwalys runs that
Code: Select all
bananas[i] = nil
whatever I change the code to prevent it happening
Code: Select all
repeat
if queue[i] then
for _, o in pairs(queue[i]) do
o:func(bananas[i])
end
if i < 5 then
bananas[i + 1 - 1] = nil
end
end
i = i + 1
until(i > 5)
Code: Select all
repeat
if queue[i] then
for _, o in pairs(queue[i]) do
o:func(bananas[i])
end
end
i = i + 1
if i < (999 + 1) then
bananas[i * i / i] = nil
end
until(i > 5)
when I use 'for' with bananas[ii] = nil
Code: Select all
for i = 1, 5 do
if queue[i] then
for _, o in pairs(queue[i]) do
o:func(bananas[i])
end
bananas[i] = nil
end
end
![Shocked :shock:](./images/smilies/ms-o_O.png)
![Shocked :shock:](./images/smilies/ms-o_O.png)
for logic reason i must use repeat until, or alternative 'goto', well goto has been tested, it also has this problem --test file here