animation help

void Keyboard (unsigned char key, int x, int y)
{

switch (key) 
{
	glPushMatrix();
	case 'r':
			glRotatef(1, 0, 1, 0); //rotate
			drawVileplume();
			break;
	glPopMatrix();
	
	//glPushMatrix();
	/*
	case 'j':
		if (up <= 50 || down >= 50) 
		{
			glTranslatef( 0, 1, 0);
			up ++;
		}
	case 'J':
		if ( up >= 50 || down <= 0 )
		{
			glTranslatef(0, -1, 0);
			down++;
		}

		break;
	*/
	//glPopMatrix();
		
case 'd':
	glPushMatrix();	
if (scale3 <= 50)
			{
				glTranslatef(1, 0, 0);
				scale3++;
			}
			check = true;
		
		
		break;
	glPopMatrix();

	glPushMatrix();
	case 'a':
		
			if (scale >= 50)
			{	
				glTranslatef(-1, 0, 0);
				scale--;
			}
		

			
	glPopMatrix();

	

	glPushMatrix();
	case 'f'://glRotatef(-1, 1, 0, 0);
			glTranslatef(0, 0, 1);  //move front
			scale2++;
			drawVileplume();
			if (scale2 >= 50)
			{
				glTranslatef(0, 0, -1);
			}

			break;
	glPopMatrix();
}

}

void doMainLoop()
{

//glPushMatrix();
	if (movingUp) // If we are moving up  
	{
		yLocation += 1.0;
	}
	else
	{
		yLocation -= 1.0;
	}
	
	if (yLocation < -80.0) // If we have gone up too far  
	{
		movingUp = false; // Reverse our direction so we are moving down  
		glTranslatef(0.0, 0.0, 1.0); // Translate our object along
		yLocation --;
		
	}
	else if (yLocation > 80.0) // Else if we have gone down too far  
	{
		movingUp = true; // Reverse our direction so we are moving up  
		glTranslatef(0.0, 0.0, 1.0); // Translate our object along
		yLocation ++;
		
	}
	/*
	if (movingUp) // If we are moving up  
		yLocation -= 1.0; // Move up along our yLocation  
	else  // Otherwise  
		yLocation += 1.0; // Move down along our yLocation  
	  
	if (yLocation < -80.0) // If we have gone up too far  
	{
		movingUp = false; // Reverse our direction so we are moving down  
		glTranslatef(0.0, 0.0, 10.0); // Translate our object alon
		yLocation ++;
	}
	else if (yLocation > 80.0) // Else if we have gone down too far  
	{
		movingUp = true; // Reverse our direction so we are moving up  
		glTranslatef(0.0, 0.0, 10.0); // Translate our object alon
		yLocation --;
	}
	*/
//glPopMatrix();

}
I am bascially making the object move to the front and back to the negative z -axis again if the object reached its max in the front. How should I do it. My animation just appear from the middle then to the end and back again without translate slowly to the front before placing it in back again. Ignore all my Keyboard code . Just on my domainLoop function which I had problem. All my global variables declared. Just the animation needs help. I did not include my whole cpp file as i think it quite huge. And my up is actually movingup is actually front. I forget to change it.

if (movingUp) // If we are moving up
yLocation -= 1.0; // Move up along our yLocation
else // Otherwise
yLocation += 1.0; // Move down along our yLocation

if (yLocation < -80.0) // If we have gone up too far
{
movingUp = false; // Reverse our direction so we are moving down
glTranslatef(0.0, 0.0, 10.0); // Translate our object alon
yLocation ++;
}
else if (yLocation > 80.0) // Else if we have gone down too far
{
movingUp = true; // Reverse our direction so we are moving up
glTranslatef(0.0, 0.0, 10.0); // Translate our object alon
yLocation --;
}This is the part where I had problem.