The boolean operator ‘If and only if’ do not have a relation with the program instruction ‘if’.
The programatic ‘if’ is a jump, not a boolean operator. It do not have truth table.
In logic:, if and iff can be seen like functions taking two booleans and returning a boolean
-
‘if a then b’ (noted a -> b): return true if a is false or b is true. Example: ‘if I eat pizza then I fart’ This is true even if I fart all the time (if b is true, we do not care about the value of a) as long as I fart when eating pizza (if a is true, b must be also true)
-
‘a <-> b’ is equivalent to ‘a -> b and b -> a’: the two should be true at the same time. I can only fart will eating pizza and cannot fart otherwise.
juliebean@lemm.ee 2 weeks ago
what would be the alternative? to always execute if the condition is true, but sometimes execute it even when false, for funsies?
bstix@feddit.dk 2 weeks ago
The “only” part implies exclusivity, which may be false, because other things might run the code anyway.
IF “I can see the sun” THEN “It’s day.”
Nothing wrong about that. However if we make it exclusive:
IF AND ONLY IF “I can see the sun” THEN “It’s day.”
That’s obviously wrong. I can actually not keep the day away by sitting with closed eyes in my mothers basement with the curtains shut.
“Only if” might make sense in a legal contract, but there’s no way a piece of code can stop other pieces of code from calling the same functions.
adj16@lemmy.world 1 week ago
But that’s not how if statements in code work. So what you’ve said isn’t wrong, but the premise of this meme is completely off
General_Effort@lemmy.world 2 weeks ago
In normal parlance, “if and only if” rules out that something could also happen as a result of other circumstances. EG, if you fall out of a plane, you will lose your glasses. But there are other conditions that would lead to the same result.
In code, the alternative would be to have a different if statement that executes identical code. Or *cough* ~you could use a jump statement to execute literally the same code.~
unmagical@lemmy.ml 2 weeks ago
Brb, making a truly “if” statement function in my products code base for funsies.