# loop refuses to run for the set amount of time

**URL:** <https://forum.makecode.com/t/loop-refuses-to-run-for-the-set-amount-of-time/45445>\
**Category:** Help\
**Created:** [August 18, 2026, 2:51am UTC](https://forum.makecode.com/t/loop-refuses-to-run-for-the-set-amount-of-time/45445 "2026-08-18T02:51:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BUM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bum/32/22127_2.png) [@BUM](https://forum.makecode.com/u/BUM)\
**Post date:** [August 18, 2026, 2:51am UTC](https://forum.makecode.com/t/loop-refuses-to-run-for-the-set-amount-of-time/45445/1 "2026-08-18T02:51:00Z")

</div>

[https://arcade.makecode.com/S25068-43644-56620-20957](https://arcade.makecode.com/S25068-43644-56620-20957)

every time i try to remove the text with the remove HUD, it recognizes the array length is 3 but the loop only runs 2 times

press a and then b to recreate

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [August 18, 2026, 3:01am UTC](https://forum.makecode.com/t/loop-refuses-to-run-for-the-set-amount-of-time/45445/2 "2026-08-18T03:01:54Z")

</div>

Use debug mode and step through your code, and watch your arrays — particularly, their lengths.

For simplicity, I’ll use the JavaScript version of one of your loops:

```typescript
    for (let index = 0; index < arrayOfText.length; index++) {
        sprites.destroy(arrayOfText[arrayOfText.length - 1])
        arrayOfText.pop()
        console.log(arrayOfText.length)
    }

```

Each time through the loop, the conditional is evaluated. Since you’re using `arrayOfText.length` in the conditional, your conditional statement _ **is changing** _ each time you go through the loop.

You just want to destroy the sprites in the array and then clear the array, yes? Do those two steps separately:

 ![arcade-screenshot (15)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/6/7/678b4e61311906d6c7d54624a8521100c9412e71.png)

> **[Empty Sprite Array](https://arcade.makecode.com/88194-27955-76719-22377)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.
