Motor and sensor

but does you're code:

boolean motorMoving = false;

replace the code to turn the motor?

for (int i = 0; i = 50; i++) //the motor turn
    {
    analogWrite(3, i);
    delay(10);
}

Or do it need some more things with it in the code?