立即退出 C++ 中的“while"循环

2021-12-26 00:00:00 while-loop break c++

如何立即退出 while 循环而不到块的末尾?

How do I exit a while loop immediately without going to the end of the block?

例如

while (choice != 99)
{
    cin >> choice;
    if (choice == 99)
        //Exit here and don't get additional input
    cin>>gNum;
}

有什么想法吗?

推荐答案

使用中断?

while(choice!=99)
{
  cin>>choice;
  if (choice==99)
    break;
  cin>>gNum;
}

相关文章