Problems with Simple leg ainmation!

Alright i’m having a problem, i have animated a simple character and wish for his legs to move back and forwards, mush like a pendulm on a clock but can’t get the code right.

Here is the cod ei am using at the moment
if (RLegAngle>=0.0 && RLegAngle<=140.0)
{
glRotatef (RLegAngle, -0.01, 0.0, 0.0);//rotate leg up by rotating by an increasing amount anticlockwise
}
else if (RLegAngle>=140.0 && RLegAngle<=280)
{
glRotatef (-140.0+(RLegAngle-140.0), 0.01, 0.0, 0.0);//move leg down by rotating by a decreasing amount anticlockwise
}

this is my rotate funsction

void myRotate (void){
if (RLegAngle == 210)
{
RLegAngle= 0.5;
}
RLegAngle+= 0.5;
glutPostRedisplay();
}

The leg moves back and then forward but when it reaches the top of the forward point it jumps back to starigh down, and i want it to smoothly rotate back down and start again

Would be great full for any help in solving this problem, either correcting this code or code to do it another way.
Thx

Check out the example in http://users.epp.teiher.gr/grafiki/files/exercises/Robot.rar
It’s from the book OpenGL Game Programming.