Most efficient way to index through an array, skipping nulls

Hi folks
I am trying to implement a hotbar for my player inventory (game is played on controller) thus they use RB/LB to navigate the hotbar, but I want the highlighter to skip to the next spot with an item, ignoring empty spots. I am pretty sure Minecraft works this way, so you have an idea of what I’m trying to do.

Anyway, I have written the following block of code that is called in my Input function that is called in Update, so this is happening every frame. I am afraid that this is an inefficient way to handle this, but I can’t think of a better way to do this.

My code below appears to work fine but I fear checking this every frame is bad
If anyone has any insight or ideas it would be much appreciated!

        if (rightBumperBool)
        {
            for (int i = inventoryIndexer; i < gunInventory.Length-1; i++)
            {
                if (gunInventory[i + 1] != null)
                {
                    inventoryIndexer = i + 1;
                    break;
                }
            }
        }
        if (leftBumperBool)
        {
            for (int i = inventoryIndexer; i > 0; i --)
            {
                if (gunInventory[i - 1] != null)
                {
                    inventoryIndexer = i - 1;
                    break;
                }
            }    

        }

Your code seems pretty fine as long as you turn your bools rightBumper and leftBumper back to false after they are turned true as to stop the for loops from running more than once.
I don’t think there’s an issue with your code but you could try using getinput

Update()
{
    if (Input.GetKeyDown(KeyCode.RightArrow))
    {
        for (int i = inventoryIndexer; i < gunInventory.Length - 1; i++)
        {
            if (gunInventory[i + 1] != null)
            {
                inventoryIndexer = i + 1;
                break;
            }
        }
    }
    else if (Input.GetKeyDown(KeyCode.LeftArrow))
    {
        for (int i = inventoryIndexer; i > 0; i--)
        {
            if (gunInventory[i - 1] != null)
            {
                inventoryIndexer = i - 1;
                break;
            }
        }
    }

You can switch the keycodes out to your preferred buttons. Getting input is fine in update. Hope this helps.