C++ 關鍵字: goto
來自 cppreference.com
[編輯] 用法
- goto 語句:作為語句的宣告
[編輯] 示例
執行此程式碼
#include <cassert> #include <string> [[nodiscard]] auto get_first_line(const std::string& string) { std::string first_line{}; for (const auto character : string) switch (character) { case '\n': goto past_for; // breaks from 'range-for loop' default: first_line += character; break; } past_for: return first_line; } int main() { assert(get_first_line("Hello\nworld!") == "Hello"); }
[編輯] 參閱
|
(C++17 起) |
|
(C++23 起) |
(C++20 起) |