How can I use "delay without delay" inside a 'for' loop?

I've used millis() as a delay replacement in multiple projects with no problem. My issue has to do with a requirement for a delay inside a for loop. If I continue because enough millis haven't occurred, the for loop continues to count (up in my case). I don't want that. I want the for loop to wait until the time has elapsed. If I use 'while the time is not up' the for loop waits (as I want) but nothing else gets executed in the program either. To me, this is no improvement over using a delay instruction. Is there another way?

If anyone is interested, the project is to replace bubble tubes on a tabletop juke box with led strips. I want the led "bubbles" to appear random so I created several bit masks that are selected at random. At the beginning of a for loop, the first position in the mask is checked (1=bubble, 0=no bubble) to control the first led. If the mask indicates no bubble I just continue (leds are already on) but to show a bubble I must turn the led off but only for a few milliseconds. I then shift the mask and with an inner loop, move all the previous bubbles one led up the strip then repeat.

Everything is working fine but I'm using delays and want to add more functions that should be executed independently of the bubbles but I'm stuck. Any suggestions?

Thank you. I really appreciate you folks being here.
-Dennis

Always best to include code to support your questions.

Don't use a for loop, let the loop() function do what it does best, ie looping

As usual when timing using millis() keep going round loop() until the period is up then do something and start the period timing again. To emulate a for loop keep count of how many periods have occurred.

I like that idea UKHeliBob. Use a counter to emulate the for loop. Sounds simple now that you've said it.

I'll do that and thank you!

-Dennis

Yes, you can.

If I use 'while the time is not up' the for loop waits (as I want) but nothing else gets executed in the program either.

The difference is you can execute stuff inside the while() loop (if that's the "stuff" you want to do).