Retrieving data from Array in Ping Pong!

Suppose I have an Array with Length 5… I want to retrieve data from an array in order like 0,1,2,3,4,3,2,1,0,1,2 and etc…I know I can do with conditional statements but I am looking for advanced mathematical expressions like

For e.g. index = (index +1) % length – > 0,1,2,3,4,0,1,2,3,4,0,1…

Something like a 5 * sin(t) + 2.5 ?

int[] myArray = new Array[5];
bool fromZero = true;
int currentIndex;
int maxValue;
int startValue;

void Start(){
  
    for(int i=0; i<myArray.Length; i++) myArray[i] = i+1;
  
    //myArray[0] = 1;
    //myArray[1] = 2;
    //myArray[2] = 3;
    //myArray[3] = 4;
    //myArray[4] = 5;
  
}

void Update(){
  
    if(fromZero){
        currentIndex = 0;
        maxValue = myArray.Length;
    }else{
        currentIndex = myArray.Length;
        maxValue = 0;
    }
  
    while(currentIndex != maxValue){
        Debug.Log(myArray[currentIndex]);
        if(fromZero)     currentIndex++;
        else             currentIndex--;
    }
    fromZero != fromZero;
}