I find it difficult to figure out how to exit a loop containing a switch statement. The gap exits the switch, not the cycle.
Perhaps this is a more elegant solution. I implemented a flag that starts as true and gets false and ends the loop. Can you suggest a better solution?
Background: This code is used in the bar code workflow system. We have handheld computers with built-in barcode scanners. This code is used in one of these functions. It asks the user for different data during the procedure. This part allows them to scroll through some inventory records displaying this information on the PocketPC terminal (paged results) and allows them to enter โDโ for โFinishโ, โQโ to exit.
Here is the current C # example that needs to be improved:
do { switch (MLTWatcherTCPIP.Get().ToUpper()) { case "": //scroll/display next inventory location MLTWatcherTCPIP.TerminalPrompt.ScrollBodyTextDown(); break; case "P": //scroll/display previous inventory location MLTWatcherTCPIP.TerminalPrompt.ScrollBodyTextDown(); break; case "D": //DONE (exit out of this Do Loop) // break; // this breaks out of the switch, not the loop // return; // this exists entire method; not what I'm after keepOnLooping = false; break; case "Q": //QUIT (exit out to main menu) return; default: break; } } while (keepOnLooping);
Here is sample code that does this in VB.NET
Do Select Case MLTWatcherTCPIP.Get().ToUpper Case "" ''
Thank,
c # while-loop break
joshblair Dec 31 '09 at 10:50 2009-12-31 22:50
source share