Break out of a while loop that contains a switch statement

One option here is to refactor this loop into a method ("extract method"), and use return.


I'd try to avoid it, but you could use...

goto

However, angry mobs with pitchforks become an occupational hazard if you choose to do so.


The only other way I know of is the dreaded goto. MSDN also says this.

However, I see no reason why you'd use it in this case. The way you have implemented works fine, and is more maintainable than a goto. I would keep what you have.


I find this form to be ever-so-slightly more readable:

bool done = false;
while (!done) 
{ 
    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) 
            done = true;
            break; 
        case "Q": //QUIT (exit out to main menu) 
            return; 
        default: 
            break; 
    } 
}