2
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by J. M. is away Oct 20 '18 at 7:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3
$\begingroup$

Use SameQ and UnsameQ instead of Equal and Unequal:

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

Hey

$\endgroup$

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