2
$\begingroup$

i want to realize an if in this way :

var=expression;

If[var==0,
Print[Hello]];

If[var!=0,
Print[Hey]];

The system doesn't know if expression is equal to zero. But i know that it is different from zero because it is symbolic. Is there a way to pass the first if with a symbolic variable?

$\endgroup$
3
$\begingroup$

Use SameQ and UnsameQ instead of Equal and Unequal:

If[var === 0, Print[Hello]];
If[var =!= 0, Print[Hey]];

Hey

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.