Scala downwards or decreasing for loop?

前端 未结 7 972
死守一世寂寞
死守一世寂寞 2020-12-13 01:56

In Scala, you often use an iterator to do a for loop in an increasing order like:

for(i <- 1 to 10){ code }

How would you d

7条回答
  •  既然无缘
    2020-12-13 02:17

    for (i <- 10 to (0,-1))
    

    The loop will execute till the value == 0, decremented each time by -1.

提交回复
热议问题