Processing an encoder

Hi everyone, I have this project with arduino nano that interface an incremental encoder (KY-040) with a car radio. My objective is to give a pulse on the output 4 if the encoder turns CW (volume up for the radio) and a pulse on the output 5 if the encoder turns CCW (volume down).
The only problem I've found is that the radio doesn't accepts a pulse under 40ms of width, and this cause a bug in the control loop, let me explain:
The control loop compares the 2 input of the encoder and discriminates if it's turning CW or CCW with an IF statement; if in this IF statement I use a delay of 40ms and I quickly turn the encoder, the program often jump one (or many) encoder pulse and it recognizes it like if it's turning in the other sense.
Result: when i'm turning CW the encoder the car radio goes up and down with the volume.

My question finally is this: is there a way to keep the control loop going on during the 40ms of delay? maybe a subroutine or something else.

I'm very noob in arduino and with this programming language the treat me like if you're explaining to your grand-dad :P)

The beginner's guide to millis() shows how to use millis() to do non-blocking timing. Another is the blink without delay sketch in the IDE examples.

Thank you very much, it's not easy to understand where to put the control of millis() during the loop but this is what I need!