how do I increment an integer variable I passed into a function in Scala?

后端 未结 5 1459
深忆病人
深忆病人 2021-01-18 05:34

I declared a variable outside the function like this:

var s: Int = 0

passed it such as this:

def function(s: Int):         


        
5条回答
  •  情深已故
    2021-01-18 05:57

    I have also just started using Scala this was my work around.

    var s: Int = 0
    

    def function(s: Int): Boolean={
    
       var newS = s
       newS = newS + 1 
       s = newS
       return true
    
    }
    

    From What i read you are not passing the same "s" into your function as is in the rest of the code. I am sure there is a even better way but this is working for me.

提交回复
热议问题