# Can't pop/delteat elements in loop

**URL:** <https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462>\
**Category:** General Usage\
**Tags:** question, array, loops\
**Created:** [June 19, 2019, 9:34pm UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462 "2019-06-19T21:34:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Post date:** [June 19, 2019, 9:34pm UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462/1 "2019-06-19T21:34:19Z")

</div>

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

 ![cantpop](https://global.discourse-cdn.com/julialang/original/3X/4/c/4c20aa7da4fe453d65618aad76915033e6c94a0a.png)  
Here’s the code(it uses CImGui library):

```julia
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)

---

<div class="post-metadata">

**Author:** ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Post date:** [June 19, 2019, 10:17pm UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462/2 "2019-06-19T22:17:24Z")

</div>

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](https://global.discourse-cdn.com/julialang/original/3X/1/f/1fba09584d007f387c2e6169912228eaded11eab.png)

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 20, 2019, 3:45am UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462/3 "2019-06-20T03:45:08Z")

</div>

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`)

---

<div class="post-metadata">

**Author:** ![wiktorkujawa](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Post date:** [June 20, 2019, 8:05am UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462/4 "2019-06-20T08:05:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 20, 2019, 6:28pm UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462/5 "2019-06-20T18:28:18Z")

</div>

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