Override Delay function

So I'm trying to program a simple motor circuit in Tinkercad with a switch and an L293D H-bridge chip. My trouble is, I've got the motor hooked up to the switch and the arduino, but I cannot seem to have the switch stop the motor cycle. I have it so that it runs forward for 5 seconds, then turns off, or, if the switch is off, it doesn't run at all. How can I have it so that the motor stops when I turn the switch off, regardless of where in the on position cycle it is? Need I a second switch? I ran into a similar question while researching this, but it didn't quite answer my question...

I'd say you could probably modify your existing code to do what you want. But, since you didn't post your code (with code tags), can't know for sure.

You can't have a switch override the delay() function. You have to re-write your sketch so that it doesn't use delay().

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking.