`do` — C++ Keyword
`do` — C++ Keyword
The do keyword in C++: executes a body at least once, then repeats while a condition is true.
`do` — C++ Keyword
The do keyword in C++: executes a body at least once, then repeats while a condition is true.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
doExecutes the body at least once, then repeats as long as the condition is true. Unlike while, the condition is checked after each iteration.
do statement while (condition);
#include <print>
int main() {
int n = 0;
do {
std::print("{} ", n);
++n;
} while (n < 5);
// Output: 0 1 2 3 4
std::println();
// Guarantees at least one prompt even if input is immediately valid
int value;
do {
std::println("Enter a positive number:");
value = 7; // simulated input
} while (value <= 0);
}
while (condition) is mandatory.do-whileint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}