Can't pop/delteat elements in loop

I can pop/deleteat only last element in my program.


Here’s the code(it uses CImGui library):

for i=1:length(S)
    CImGui.PushID(i-1)
    CImGui.Text("Line nr $i: $(S[i]) \n")
    CImGui.SameLine()
    CImGui.Button("X") && (deleteat!(S,i-length(S)+1))
    CImGui.PopStyleColor(3)
    CImGui.PopID()
end

Same goes with pop!(S)

Ok, that is not a problem with pop, but with CImGui.Text.
Now I can pop(I pop before, but there was problem with reading last element after pop) , but can’t describe element and idk how to do it.
updatepop

I think 1:length(S) will freeze the length of S before the deletes, and so will walk over already deleted/inexistent elements. Have you tried to use a while loop instead? (e.g., i = 1; while i <= length(S); ...; end)

1 Like

That one I didn’t check. My fault. Now everything works. Thanks.

No problem. I thought of that because I did the same mistake recently.