Can someone help me to improve my code? IR remote control to control Motor

well, what i mean is i have 4 programmed button on IR remote control:
Buttons:
1 - spin motor clockwise 4 times with pause and counter clockwise 4 times.
2 - spin motor on maximum.
3 - spin motor in reverse on maximum.
5 - Stop motor.

So what i need help is to make whenever press button "1" motor start spinning clockwise and counter clockwise infinitely. But whenever i press any other button such as "2" or "5" it will come out from infinite function and perform actions from pressed button.
i hope this can help you to understand what i want to achive.
thank you