+ 1
if-else is how you would start a conditional check, to check if a certain expression is true, and if not, it'll run the else code. else-if is what is chained on to if-elses to extend them in such a way where for example a user can enter multiple valid inputs. These inputs could be strings for example, as they are not compatible with switch statements, which is the prefered method compared to chained if-elses. string str = "Cool"; if (str == "Hi") cout << "str is Hi"; else if (str == "Hello") cout << "str is Hello"; else if (str == "Cool") cout << "str is Cool"; else cout << "Unknown string"; //output is "str is Cool".
22nd Nov 2016, 4:05 PM
Cohen Creber
Cohen Creber - avatar