Scala 2.8 中有 do-until (后置条件)循环吗?

发布于 2024-09-26 02:35:29 字数 79 浏览 0 评论 0原文

如果我可以使用后置条件(do-until)循环而不是前置条件(while)循环,我的算法可能会更具可读性。 Scala 2.8中有这样的功能吗?

An algorithm of mine could be better readable if I could use a postcondition (do-until) loop instead of precondition (while) loop. Is there such a feature in Scala 2.8?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见 2024-10-03 02:35:29

当然。

scala> var i = 0
i: Int#4363 = 0

scala> do {
     | println(i)
     | i += 1
     | } while (i < 10)
0
1
2
3
4
5
6
7
8
9
res0: Unit#3773 = ()

Sure.

scala> var i = 0
i: Int#4363 = 0

scala> do {
     | println(i)
     | i += 1
     | } while (i < 10)
0
1
2
3
4
5
6
7
8
9
res0: Unit#3773 = ()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文