How to access each item from the loop via return function

The easiest way to this is to not do it. Instead, just have a global array of values, and store the values you want to save into that array.

// At the top level:
float[] allDistances = new float[10];

// Inside your function:
allDistances[i] = whatever;

// Outside that function, but elsewhere:
if( allDistance[i]  > whatever ){