Originally posted by Shriya Kishore: Y cant they just write simple if statements
Please use real words when posting to the forums. Abbreviations such as "y" in place of "why" only serve to make your posts more difficult to read and less likely to generate useful responses.
Originally posted by Shriya Kishore: Y cant they just write simple if statements
The ternary operator can be very useful and terse when making a simple decision in an expression. It can also be confusing when used as shown in your example. A judicious mix of if statements and the ternary operator can be used to achieve code that is as brief as possible, while still being readable and clear.
A good dose of thoughtful code formatting can also go a long way to enhancing the clarity of the code.