Millis cycle ending with same value?

Hello, iam have one small problem. Iam must use cycle without delay (via millis). Iam have connect flowrate sensor to arduino and beeper. Millis cycle is for beeper, every 500 sec do tone or notone, but problem is , when flowrate sensor is ending, beeper stop on "on" or "off". How to change it, the beeper is always off when flowrate sensor is too? Cycle is here :

          if(flowrate > refresh)
          {
            refresh = flowrate;
            if(currentTime >= (cloopTime1 + 500))
            {
              cloopTime1 = currentTime;
              switch(val)
              {
                case 1: val = 2; tone(6,3000); break;

                case 2: val = 1; noTone(6); break;
              }
            }
          }

How you can see, when is flowrate sensor moving, beeper is "beeping" but there is 50% it will stop on beeper "on" or 50% beeper will stop on beeper "off"

Thanks for help.

One thing, you should change

            if(currentTime >= (cloopTime1 + 500))

to

            if(currentTime - cloopTime1 >= 500)

or you will have problems when millis() overflows.

To answer your main question, just run noTone() after the cycle is complete.