refactor (only) of doswitch()
Merge pull request #2295 from WalterBright/refactor-doswitch

refactor (only) of doswitch()