THE WRITER MUST EAT -> patreon.com/trn1ty <- | \ | | blah! |\ | `\|\ | the rantings and ravings |/ |(_|| | * of a depraved lunatic <^> 2022-10-25 i am logical, if not for time In C conditional logic is usually expressed in if statements. The very narrow textbook example of this is thus: if (condition) { do_something(); } else { do_another_thing(); } I don't like this. There are a couple of supposed truths within this example that are false: - brackets are necessary for the if statement body (they aren't) - ifs are the only way to perform conditional logic in C (they aren't) this may not be stated outright in the example, but it's implicit in that it's the only way textbooks will show much logic This "blah" doesn't exist to express solid facts, just my loose and flimsy opinions and experiences. Here are four ways to do something in C that are each functionally identical to each other: bool aisfive(bool c, int *a) { if (c == 1) { *a = 5; } else { *a = 6; } return a; } bool aisfive(bool c, int *a) { if(c) *a = 5; else *a = 6; return a; } bool aisfive(bool c, int *a) { *a = c ? 5 : 6; return a; } bool aisfive(bool c, int *a) { *a = 5 + !c; return a; } I prefer the bottom-most example but the difference won't matter to a good compiler. To me, algebraic expression is just as good as if-else expression. But I'm an Internet crank that's still programming in C. <^> No rights reserved, all rights exercised, rights turned to lefts, left in this corner of the web.