I tried with AS2 to animate the movement of a cylinder going non stop up and down and with possibility to change speed. I managed the sliding down and the acceleration of the cylinder but it does not recognize the limit where it has to stop and make the movement backwards to starting position.

Please help me out, I'm not very expert in programing and I'm not able to recognize what the problem is.

Here the code applied directly to the MC:
onClipEvent (load) {
	// Initial position
	this._y = 50;
	// Starting Speed
	var _velocidad = 10;
	// Acceleration
	var _accelera = 5;

onClipEvent (enterFrame) {
	// Speedup
	this._velocidad = Math.round((this._velocidad+this._accelera)*100)/100;
	if (this._y>=50) {
		this._y += this._velocidad;
	} else if (this._y<=500) {
		this._y -= this._velocidad;