Decreasing for loop in Scala?

前端 未结 8 929
一生所求
一生所求 2020-12-17 20:24

First day and first attempt at using Scala - so go easy on me! I\'m trying to rewrite some old Java code I have which is simply a function which takes two numbers and prints

8条回答
  •  囚心锁ツ
    2020-12-17 21:16

    highnum to lownum by -1 (switch with other negative or positive step to change stepping)

    def decrement(start: Int, finish: Int) = {
      for (i <- start to finish by -1) {
         println("Current value (decreasing from "+start+" to "+finish+") is "+i)
      }
    }
    

    I think this is a dupe of Scala downwards or decreasing for loop?

提交回复
热议问题