= is not a member of Uni...">

Scala when assigning a loop

I am trying to port some Java code to Scala:

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

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

Is it impossible?

+6
source share
1 answer

Assignments return () (unit) in Scala. But this is normal, because you can put a block of code anywhere. You need it:

 while ({ j=f("blah"); j } >= 0) ... 
+16
source

All Articles