Looping outside of void Loop

I'm just figuring this out so pardon any possible poor explanation or terminology.

The basic is, I'm trying to control a servo like an oscillating fan. It moves from 0 to 180 and then back constantly in a do/while loop.

This do/while is activated once the ON trigger is sent (in this case for the fun of it it's and RFID key fob).

The problem I'm having is, while this do/while is going to keep the servo oscillating the program is locked in that state. By that I mean the other things I want to constantly check in void loop() are not being processed, such as "is someone trying to change the speed", "are they trying to turn it back off".

OFF/ON is controlled by the RFID card so I can easily have a check for the card in the do/while, but as far as the changing speed issue, I haven't figured that out yet.

I want the fan to keep moving but adjust speed without interruption. (To note: Speed change is also done by RFID just a different card - RFID is not necessary I just wanted to learn it as well so 2 birds 1 stone).

Lets say I move the fan control to a different thing like a button that when pressed cycles through speeds 1 thru 3. Will that help? Either way I'm still not sure how to keep an eye on other inputs if I'm locked into that do/while for the oscillating so the servo smoothly moves.

The solution to your problems is the same as the BlinkWithoutDelay example sketch shows for another situation where the delay() call is used (I'm quite sure that you use it in your loop too).

OK, so you've got blocking code. It goes to the while loop and then the do-while loop doesn't exit until the entire story of the fan movement has been told.

You need a non-blocking solution. Instead of deciding if the fan needs to move and then moving it through the entire range of motion, decide that the fan needs to move and move it one tiny step and then let the whole process repeat. On any run through the loop function you only move the fan by some small amount and then go around to check again.

Take a look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Also, if you are using a DUE, STM32, or ESP32 you can use freeRTOS which will give your code a great task switching ability.