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

后端 未结 8 523
-上瘾入骨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:16

    let bubbleSort (a: _ []) =
      let mutable fin = false
      while not fin do
        fin <- true
        for i=0 to a.Length-2 do
          if a.[i] > a.[i+1] then
            let t = a.[i]
            a.[i] <- a.[i+1]
            a.[i+1] <- t
            fin <- false
    

提交回复
热议问题