在while循环外声明的变量在scala中的while循环内不可访问

Dan*_*all 1 scala intellij-idea

我试图让我的头围绕scala循环.

我有以下代码:

var basicInteger = 0
var finished = false
while(!finished) {
     basicInteger += 1
     finished = true
}
Run Code Online (Sandbox Code Playgroud)

当我单步执行此代码时,变量basicInteger变得不可访问,并且intellij ide告诉我它找不到局部变量basicInteger.

是否可以在scala中的while循环中引用外部定义的变量?

slo*_*ouc 7

这与IntelliJ IDE调试器有关.您的代码完全有效.