how to exit nested loops

后端 未结 6 1233
予麋鹿
予麋鹿 2021-01-21 20:11

i have something like

   while(playAgain==true)
   {
      cout<<\"new game\"<

        
6条回答
  •  半阙折子戏
    2021-01-21 20:40

    There are basically two options to go.

    1. Add the condition check in outer loop.

      while ((playAgain==true) && (decision != '\n'))

    2. Simply use goto. People are often told never to use goto as if it's monster. But I'm not opposed to use it to exit multiple loops. It's clean and clear in this situation.

提交回复
热议问题