Why “do…while” does not exist in F#

后端 未结 8 521
-上瘾入骨i
-上瘾入骨i 2021-02-04 00:36

I cannot find \"do...while...\"

I have to code like this:

let bubbleSort a=
    let n = Array.length a
    let mutable swapped = true
    let mutable i =         


        
8条回答
  •  一个人的身影
    2021-02-04 01:28

    You can do something like

    let mutable ind = 0
    while (
        //Do your stuff here
    
        //Now condition part return some boolean value
        ind < 10
    ) do ind <- ind +1
    

    I just recently found this way. It feels a bit hacky but what I like is that you can build something more complex what usually caused issues in C#, C++.

    let mutable ind = 0
    while (
        (some condition) && (
        //do something
        let someValue = Eval ....
    
        //Now more complex condition
        ind + someValue < 10
        )
    ) do ind <- ind +1
    

提交回复
热议问题