Why "do...while" does not exist in F#

Posted by Kev on Stack Overflow See other posts from Stack Overflow or by Kev
Published on 2010-06-10T07:44:07Z Indexed on 2010/06/10 8:52 UTC
Read the original article Hit count: 264

Filed under:

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 = 0
    while swapped do
        swapped <- false
        for j = 0 to n-i-2 do
            if a.[j] > a.[j+1] then
                let t = a.[j]
                a.[j] <- a.[j+1]
                a.[j+1] <- t
                swapped <- true
        i <- i+1

The code is bad without "do...while".
Sadly, "break/continue" are also not available.
Is F# not suitable for non-functional-programming?

© Stack Overflow or respective owner

Related posts about F#