Call function to print several times in the same order

I want to call a function which prints values with a certain delay.

The call statements should always follow the same order.

I tried to increase the caller id with id++ but as the function calls dont always happen in the same order the if conditions that I implemented wouldnt resolve the problem. The following is the only code that I could come up with that worked. The problem is that the ids are static. Which of course makes it very annoying if new code is added or inserted.

#define INTERVAL 1000
byte id = 0;

void setup()
{
  Serial.begin(115200);
    while (!Serial);
}

bool delay_without_delaying(byte &idDelay, unsigned long time) {
  // return false if we're still "delaying", true if time ms has passed.
  // this should look a lot like "blink without delay"
  static unsigned long previousmillis[50];
  unsigned long currentmillis = millis();
if (currentmillis - previousmillis[idDelay] >= time)
{
    previousmillis[idDelay] = currentmillis;
        Serial.print("id_alt: ");
        Serial.println(idDelay);
        idDelay++;
        Serial.print("idDelay: ");
        Serial.println(idDelay);
        return true;
    }
    return false;
}

void loop()
{
if ( id == 0 )
if ( delay_without_delaying(id=0, INTERVAL) )
{
  Serial.print("id0: ");
  Serial.println(id);
}
if ( id == 1 )
if ( delay_without_delaying(id, INTERVAL) )
{
  Serial.print("id1: ");
  Serial.println(id);
}
if ( id == 2 )
if ( delay_without_delaying(id, INTERVAL) )
{
  Serial.print("id2: ");
  Serial.println(id);
  id = 0;
}
}

What better way is there to achieve this?

Thank you for your help!

Did you want them all to print in order all at once every INTERVAL or to print in order but separated by INTERVAL? Either can be done but it is not clear from your sketch which you intended.

The way you are doing it now, if id0 is called just before the timer expires and id1 is called just after the timer expires, id1 and id2 will happen before id0.

You claim that this works. How? the variable 'id' is never modified in loop().

What is this program supposed to do?

aarg:
You claim that this works. How? the variable 'id' is never modified in loop().

Note that 'id' is passed by reference.

johnwasser:
Note that 'id' is passed by reference.

Oh I see now. It is interesting that the function that modifies 'id' by reference, delay_without_delaying(), is called inside loop().

Thank you johnWasser and aarg

The code supplied was just a try with minimal code to see how it works.

What I want to do is:
I have a larger project. So far I had a tab in the ide for debugging. It contained all sensors and was enclosed in a blink without delay kind if statement to slow serial output down.

Now I want to integrate the respective sensor values in the rest of the skript to be able to allow for different types of debugging:
sensor, warning, error

and different sensors types.

which I would define as follows:

#define SENSOR_DEBUG true

and than have it actived in the skript:

#if SENSOR_DEBUG
// delay statement and sensor value and other code go here
#endif

the delay_without_delaying should serve to slow the output down. The id was initially used for the previousMillis array. I didnt expect the outputs to be in a random order and especially not that one sensor might be printed 3 times and another would print at all in the same time. That's why I tried to use the id as well to structre the output.

I realized that my approach with the static ids wont work or will only work for the sensor values which are all printed in the same order. On the other hand the warning and error statements will appear in a random order. Therefore I think that I would still need some other way than the static ids to specify the function calls to have them printed one after the other while allowing for additional data like warnings and errors to take place.

Concerning your question johnwasser:
basically I was thinking to print them all at once. On the other hand it would be happy to know both ways of doing it.

I would be very happy if you could give me some ideas on how to improve the code.