Spec-Zone.ru › C++

C++ keyword: goto

Использование

  • 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");
}

См. также

  • if оператор: if, else
  • constexpr if оператор: constexpr (оператор constexpr if)
(начиная с C++17)
  • consteval if оператор: consteval (оператор consteval if)
(начиная с C++23)
  • switch оператор: switch, case
  • default (в качестве объявления метки case) и т. д.: default
  • continue оператор: continue
  • break оператор: break
  • return оператор: return
  • co_return оператор (возврат из сопрограммы): co_return
(начиная с C++20)
  • do-while цикл и while цикл: do, while
  • for цикл и цикл for с перебором диапазона: for

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/keyword/goto

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API