How to write a condition in which the 3 variables are not equal to each other?

There are 3 variables hero , smoke and recycle . I need them to be all not equal to each other, i.e. contained different meanings. How to describe it in the condition?

Here such code does not work:

 smoke != hero && smoke != recycle && recycle != hero 
  • 2
    what is meant by "not working"? - Isaev

1 answer 1

This condition can be written like this.

 let hero = 0, smoke = 1, recycle = 2 if !(hero == smoke || hero == recycle || smoke == recycle) { print("Все 3 переменные не равны друг другу") } else { print("Какие-то из переменных равны друг другу") } 

Print will issue:

 Все 3 переменные не равны друг другу 
  • Why didn’t the TC code work?) - diraria