need help pwm motor

Hi, I Need help writing a Program which does the following: After pushing a button the engine should start slowly running up to a certain speed and keep running until you push the button again - then it should stop slowly.

I use an Arduino Uno, the engine is on Pin 10 the Switch on Pin 9.

Thanks!

void loop(){
if ((digitalRead(button) == LOW) && motorRunning == 0){ // motor stopped, let's go
motorRunning = 1;
for (int x=0; x <=255; x=x+1){
analogWrite(pwmPin, x);  // play with amount x increments by
delay(5); // give motor a chance to respond, maybe longer
}
if ((digitalRead (button) == LOW) && motorRunning == 1){ //motor going, let's stop
motorRunning = 0;
for (int x=255; x >=0; x=x-1){
analogWrite(pwmPin, x);  // play with amount x decrements by
delay(5); // give motor a chance to respond
}

Later change this to blink without delay vs delay(5) so can be doing other things.

Need some more }s in there to close out if's and to close out loop.