I'm trying to write a for loop that starts from where my currentIndex variable leaves off, and traverses through the circular buffer.
I am using the circular buffer to store load data. Data is periodically stored.
Currently, this is how I populate data:
//currentIndex starts at 0
buffer[currentIndex] = data;
currentIndex = (currentIndex + 1) % size;
Ex: size is 6. 8 entries (1 2 10 11 12 13 8 9) are stored, so 2 entries at index 0 and 1 get overwritten.
Index : 0 1 2 3 4 5
Buffer: 8 9 10 11 12 13
After 9 is populated, currentIndex becomes 2. I want to traverse indices in this order: 9, 8, 13, 12, 11, 10. I want to start from the last index (most recent data) populated.
I am having trouble coming up with the logic to do this in a for loop.