Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala while loop assignment

Tags:

java

scala

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?

like image 530
sucasa Avatar asked Mar 03 '13 23:03

sucasa


1 Answers

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) ...
like image 161
Rex Kerr Avatar answered Oct 30 '22 18:10

Rex Kerr