gpt4 book ai didi

scala - Scala 中 for 循环加 2

转载 作者:行者123 更新时间:2023-12-01 16:51:22 25 4
gpt4 key购买 nike

如何将循环增加 2,相当于 Java 中的循环:

for (int i = 0; i < max; i+=2)

现在在 Scala 中我有:

for (a <- 0 to max)

事实上,max 始终是偶数。我不知道如何在每个循环中将计数器增加到 2。

最佳答案

尝试for (a <- 0 until max by 2)

关于scala - Scala 中 for 循环加 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17791464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com