從c中脫離循環
In this example, the goto statement jumps to the label exit_loop when the state is set to DONE, effectively breaking out of both the switch statement and the while loop.
Using a Flag Variable
An alternative approach is to use a flag variable.這可以是一個布爾變量,當在開關語句中滿足所需條件時,它將設置為true。然後,可以通過在Switch語句之後檢查標誌變量來打破循環。 這是一個示例:
在這種情況下,當將狀態設置為完成時,syse_exit標誌將設置為true,並且當在Switch語句之後檢查標誌時,循環被打破。免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3