[c++] How to break out of a loop from inside a switch?

I'm writing some code that looks like this:

while(true) {
    switch(msg->state) {
    case MSGTYPE: // ... 
        break;
    // ... more stuff ...
    case DONE:
        break; // **HERE, I want to break out of the loop itself**
    }
}

Is there any direct way to do that?

I know I can use a flag, and break from the loop by putting a conditional break just after the switch. I just want to know if C++ has some construct for this already.

This question is related to c++ loops syntax switch-statement break

The answer is


You can use goto.

while ( ... ) {
   switch( ... ) {
     case ...:
         goto exit_loop;

   }
}
exit_loop: ;

Similar questions with c++ tag:

Similar questions with loops tag:

Similar questions with syntax tag:

Similar questions with switch-statement tag:

Similar questions with break tag: