2
$\begingroup$

I have the following code

test[variable_: 0] := Module[{},
   If[variable != True, Print["worked"]];
   ];

test2[variable_: 0] := Module[{},
   If[variable == True, Print["worked"]];
   ];

If I run

test2[True]

I get "worked" as I expect.

But if I run

test[] 

I return nothing. Why is this the case?

$\endgroup$
3
  • 6
    $\begingroup$ == can't say anything about the equivalence between 0 and True. You want =!= and === instead. $\endgroup$
    – C. E.
    Jul 5, 2018 at 23:11
  • 2
    $\begingroup$ Or just use TrueQ $\endgroup$
    – b3m2a1
    Jul 5, 2018 at 23:15
  • $\begingroup$ try to evaluate 0!=True and/or 0==True and see what happens $\endgroup$ Jul 6, 2018 at 6:41

0

Browse other questions tagged or ask your own question.