The most basic concepts of almost any programming language are conditional statements and loops. We are going to explore them in detail.
Control flow
Conditionals
It's hard to imagine a program that doesn't contain a conditional statement. It's almost a habit to check the input arguments of functions securing their safe execution. For example, the divide() function takes two arguments, divides one by the other, and returns the result. It's pretty clear that we need to make sure that the divisor is not zero:
int divide(int a, int b) {
if (b == 0) {
throw std::invalid_argument("The divisor is zero");
}
return a / b;
}
Conditionals are at the core of programming languages; after all, a program...