Loop-switch sequence
Appearance
A loop-switch sequence is a specific derivative of the spaghetti code programming antipattern which achieves its crapulence from the obfuscating of a clear process of steps with a byzantine switch-within-a-loop idiom. However, it is not necessarily an anti-pattern to use a switch within a loop to build a coroutine using a finite state machine.
Example of Antipattern (pseudocode)
String key; String value; List<String> args; for ( int i = 0; i < 5; ++i ) { switch( i ) { case 0 : key = stream.parse(); break; case 1 : value = stream.parse(); break; default: args.add( stream.parse() ); } }
Refactored Solution (pseudocode)
String key = stream.parse(); String value = stream.parse(); List<String> args; for ( int i = 0; i < 3; ++i ) { args.add( stream.parse() ); }