gpt4 book ai didi

C++ Try Catch 内部循环

转载 作者:太空狗 更新时间:2023-10-29 20:05:40 25 4
gpt4 key购买 nike

我有一个具有以下通用结构的 C++ 程序

1st while (condition A == true)
//some code for 1st loop

2nd while (condition B == true)
//some code for 2nd loop
try
//some code for try
catch
//condition B == false (supposed to leave 2nd loop and go back to first loop)

我希望它在出现异常时退出第二个循环并返回到第一个循环,直到条件 B 再次成为 tue。如上所述,它没有像我预期的那样工作。似乎正在发生的事情是代码卡在 catch 中并且永远不会离开它。

我如何安排它才能按我的需要工作?

注意:条件 A 永远不会为假。

最佳答案

将break关键字添加到catch中

另请注意,您有 b == false;那是检查 b 是否等于 false,而不是设置 b = false。

关于C++ Try Catch 内部循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12222947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com