how to start counting from the last index the script stop on?

i’m making an audio Visualization script.

i want to split the samples into 4 bands for example, but i can’t figure out how.

i know i need to have a variable that’s hold the last index the loop stop on it
but how to make it start from this variable.

i have wrote a script but its not doing the job.

and all the index in _Bands have the same value(Which is what I don’t want).

*_Band its a list and its size change according to the enum" _NumberOfBand".

*_Samples its an array hold 64 samples.

here a part of it:

        void MakeBands()
        {
            int _Count = _Samples.Length / (int)_NumberOfBands;
            int _index = 0;
            
            for (int i = 0; i < (int)_NumberOfBands; i++)
            {
                float _sum = 0;
                
                for ( int i2 = _index; i2 < _Count; i2++)
                {
                    _sum += _Samples[i2];
                    
                }

                _Count = _Count + (int)_NumberOfBands;
                _Bands *= _sum;*

}

}

You can just add a variable end and add it to i2.

void MakeBands()
         {
             int _Count = _Samples.Length / (int)_NumberOfBands;       
             float _end = 0;
             for (int i = 0; i < (int)_NumberOfBands; i++)
             {
                 float _sum = 0;
                 for (int i2=0;i2<_Count;i2++)
                 {
                     _sum += _Samples[i2+_end];
                 }
                 _end = i2;
                 _Bands*=_sum;*

}

}

ok i figure it out by my self, thank you @Krunoslav for your help.

        void MakeBands()
        {
            int _Count = _Samples.Length / (int)_NumberOfBands;
            int _index = 0;
            
            for (int i = 0; i < (int)_NumberOfBands; i++)
            {
                float _sum = 0;
                
                for ( int i2 = _index; i2 < _Count; i2++)
                {
                    _sum += _Samples[i2];
                    _index = i2;
                    
                }

                _Count = _Count + (int)_NumberOfBands;
                _Bands *= _sum;*

}

}
}