I'm just getting started in F# and have a basic question.
Here's the code:
let rec forLoop body times =
if times <= 0 then
()
else
body()
forLoop body (times - 1)
I don't get the concept of how when you define a variable it is a value and immutable. Here, the value is changing in order to loop. How is that different from a variable in C#?
it is not changing. you use recursion. that variable remains unchanged, but it is subtracted one and passed to function. function is same in this case.
stack will look like
forLoop body 0
|
forLoop body 1
|
forLoop body 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With