C++ provides many ways to test values and loop through code.
Controlling execution flow
Using conditional statements
The most frequently used conditional statement is if. In its simplest form, the if statement takes a logical expression in a pair of parentheses and is immediately followed by the statement that is executed if the condition is true:
int i;
std::cin >> i;
if (i > 10) std::cout << "much too high!" << std::endl;
You can also use the else statement to catch occasions when the condition is false:
int i;
std::cin >> i;
if (i > 10) std::cout << "much too high!" << std::endl;
else std::cout << "within range"...