A machine may need one inspection before the program can decide whether another inspection is needed. A do-while loop expresses that order: perform the body first, then test whether to repeat.
#include <iostream>
int main() {
int checks = 0;
do {
checks = checks + 1;
} while (checks < 2);
std::cout << "Checks: " << checks << '\n';
return 0;
}
do introduces the body. The condition comes after its closing brace, and this form requires a semicolon after while (...). Here the first body execution changes checks to 1. The condition is true, so the body runs again. At 2, the condition is false and the loop ends.
Trace the first action before comparing the loop forms. A while checks before entering its body, so it can skip the work entirely. A do-while reaches its condition only after the first body execution. That makes it suitable when the work must happen once even if no repetition is needed.
Your starter models a quick equipment inspection. The requested repeat count is 0, but the initial inspection must still happen. Add a do-while that increases inspections once per body execution and repeats while inspections < requested. The output statement is already present. With the supplied values, this should report one inspection, not zero.
Use this structure only when that first action really is required. It is not a safer replacement for every while; both forms still need a state change that makes repetition stop.
do-while loop that increases inspections by 1, then repeats while inspections < requested. The existing line should print Inspections: 1.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.