How to work with 4 sets of data and 2 variables?

vaj4088:
This would work also. I usually avoid division - which is what the modulo operation may entail for values that are not a power of two - but division is likely to be quicker than moving a bunch of data. Good one!

well also in that case since it's a simple circular buffer you can do it with no division at all since it's just moving one position by one position

you need

  • a boolean stating if the array has been fully populated, starts at false
  • an index going through the array

when the boolean is false, data captured are in 0..index
when the boolean is true, you have historical valid data in the array and you can iterate through the array from most recent to oldest with just two for loops (index-1 to 0 whilst >=0) and (max size - 1 to index)