Most likely, the code you found uses for loops and delay() to run through a complete "pattern" before reading the switch again.
You can read the switch state and break out of the loop, but you can't do anything about the delay()s, without completely rewriting the sketch to be a state machine.