Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+16 votes

Are there any ways shorter to write the condition of if/else statement which compares 3 values than "If ( value1 == value2 && value2 == value3) {... " ?

Practice it counts "if (value1 == value2 == value3) {..." as error

asked in CSC211_Winter2018 by (1 point)

2 Answers

+12 votes

No because == is a relational operator that can only compare two operands. The code that you tried would compare the first two and find it to be true or false and then compare true/false to value3 which results in the error.

answered by (1 point)
+10 votes

I don't think there is another way of comparing 3 values other than using && or || statements, in this example.

answered by (1 point)