stepper.h - change stepper speed inside loop()

I've tired placing the stepper.setSpeed(xxx); inside void loop(), but the stepping sequences didn't work. Is there a way for changing the speed while the program is running?