Take the 2-minute tour ×

I'm trying to port some Java code into Scala:

while ((j=f('blah'))>=0) ...

ERROR:"value >= is not a member of Unit"

Is this not possible?

share|improve this question
If you really need that, you're doin it rong... –  Landei Mar 4 '13 at 9:36
add comment

1 Answer

up vote 5 down vote accepted

Assignments return () (unit) in Scala. But that's okay because you can put a code block anywhere. You need this instead:

while ({ j=f("blah"); j } >= 0) ...
share|improve this answer
The reasoning for that can be found here: What is the motivation for Scala assignment evaluating to Unit rather than the value assigned? –  EECOLOR Mar 3 '13 at 23:23
lifesaver thanks –  user1550052 Mar 4 '13 at 0:00
add comment

Your Answer


