sure, the original 'if' statement is the catalyst, the else statements are conditional expressions related to the original, as soon as the first else/if expression in the ladder is found true, then all following else ifs in the ladder are disregarded(even if they are true as well), therefore they are inherent to the original if statement and not independent, if no else statement is found true it the default statement at the end of the ladder is usually just that a default output and why the program works. it IS an extended if expression
lol ok, , and have a good night btw :D but tell me why this program wont display all if's statements they are all true? because they are part of an extended if statement.
#include <iostream>;
usingnamespace std;
int main()
{
int a;
a=4;
if(a==4)cout << "you wont read anything beyond this even though the following if statements are all true\n";
elseif(a==4)cout << "just\n";
elseif(a==4)cout << "making\n";
elseif(a==4)cout <<"my \n";
elseif(a==4)cout << "point\n";
elseif(a==4)cout <<"lol\n";
return 0;
}
oh that's cool, I thought it could only be used in cases of if/else but I'm guessing if the above works then you can have multiple if/else if/else if/else if/else if/else statements. assuming you stay approx around/below the 80 char limit.
because they are part of an extended if statement.
There's no such thing as "extended if statement". Only the first true block is executed because all the other if statements are inside the false block of the outermost (i.e. the first) if statement.
80 char limit for printers. I usually try to keep my code below this. so for example a cout statement that is 300 chars long can be broken up and put on 4-5lines; eg.
1 2 3 4
cout << "Hello World, My name is " << name << ". I like to dance on the moon with "
<< alien_Name << endl << "Because he teaches me lots of cool things like: "
<< move1 << " and " << move2 << " and " << move78 << "." << endl
<< "Also he has great alien weed, and a " << alien_spaceship << endl;
as far as C++ goes, you can pretty much have a 5000 line program on the 1 line. But it's pretty damn poor practice and virtually impossible to read.
I guess the question should be asked can you include whitespace (newlines) within extended if's?
condition ? function : condition ?
function : condition ? function : function
Trinary operator, ternary operator, or conditional operator.
Limiting yourself to 80 characters doesn't make sense unless you expect to read your code on a console or you're going to print it with a dot matrix printer.