[英]Assign to a variable in the condition of a while loop - scala
I Java I can write this: 我是Java我可以写这个:
Matcher m;
while ((m = pattern.matcher(string)).matches()) {...}
How would I do this in Scala? 我如何在Scala中执行此操作? This doesn't work :
这不起作用:
var m: Matcher = null
while ((m = pattern.matcher(s)).matches()) {}
Assignments return Unit
in Scala, but it's ok to use code blocks like this: 赋值在Scala中返回
Unit
,但是可以使用这样的代码块:
while ({
val m = pattern.matcher(s)
m.matches
}) { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.