Once again you can see that in C++ the curly braces define a block rather than indentation. In C++ the parenthesis around the condition are required because if is technically a function that evaluates to true or false.
C++ does not have an elif pattern like Python. In C++ you can get the functionality of an elif statement by nesting if and else. Here is a simple example in both Python and C++.
We can get closer to the look of the elif statement in C++ by taking advantage of the C++ rule that a single statement does not need to be enclosed in curly braces. Since the if is the only statement used in each else we can get away with the following.
C++ also supports a switch statement that acts something like the elif statement of Python under certain conditions because the statement takes cases and checks the validity of the case against the code. It uses cases instead of conditions and the case must be based on integers or a user-defined data type called an enumerated constant.
Frankly, the switch statement is not used very often. It is not as powerful as the else if model because the switch variable can only be compared for equality with an integer or something called an enumerated constant. Second it is very easy to forget to put in the break statement. Note above how cases 10 and 9 are coded together. If the break statement is left out then then the next alternative will be automatically executed. For example if the grade was 95 and the break was omitted from the case 9: alternative then the program would print out both (A and B.) So, you might want to just avoid it and use ifβ¦