Namespaces
Variants

C++ keyword: while

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

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

  • while цикл: как объявление цикла
  • do-while цикл: как объявление завершающего условия цикла

Пример

#include <iostream>
int main() noexcept
{
    int i{3};
    // Следующий оператор цикла 'while':
    // 1. (условие) Проверяет, больше ли значение переменной 'i' нуля
    //                и если нет, завершает выполнение цикла в этой точке.
    //                Пост-декрементирует переменную 'i' (уменьшает её значение на 1).
    // 2. (оператор) Выводит текущее значение переменной 'i' в stdout.
    // 3.             Возвращается к пункту 1 (условие).
    while (i --> 0)     // condition: i-- > 0
        std::cout << i; // statement: std::cout << i;
}

Вывод:

210

Смотрите также

(начиная с C++17)
(начиная с C++23)
(начиная с C++20)