C++ キーワード: goto
From 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以降) |