How does "while / do" work in Scala 3?

Asked

Viewed 19 times

1

Reading the changes planned for Scala 3, I discovered that the do-while was discontinued. I understand that a loop do-while can always be rewritten as a while. That said, the article examples with a while followed by do are a little hard to understand.

while
   i += 1
   f(i) == 0
do ()

And another example:

while
   val x: Int = iterator.next
   x >= 0
do print(".")

How does this construction work? It seems to me that the condition is in the last command in the body of while, and that the do will only be executed if that condition is true. My understanding is correct?

  • Part of my initiative to bring more questions to the community.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.