Dave's Brain

Browse - Programming Tips - What is the Scala equivalent to the C question mark?

Date: 2013may14
Language: Scala
Level: Beginner

Q.  What is the Scala equivalent to the C question mark?

A.  In C:

return a > b ? a : b // Return the max
In Scala:
return if (a > b) a else b

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.