Programming error

U didnt understood ..... In this code which ive uploaded i`ve moved my servo from 0 to 180 and sensor takes reading at every degree... and prints distance(a) on the serial port ....

what i want to do is that once the servo has moved to 180 deg i want to move it in opposite direction to 0 deg... and repeat the same procedure with the sensor... but what i want to print on the Serial port is the average distance of both cycles ...