2

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
siderius
  • 155
  • 6

1 Answers1

3

Use SameQ and UnsameQ instead of Equal and Unequal:

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

Hey

kglr
  • 394,356
  • 18
  • 477
  • 896