f# for 循环继续

f# for loop continue

我希望在 else 循环之后继续,这样列表将被填充,然后是 return 列表

let isPoli num =
    let x = string num
    let fhf = x.Substring(0, (int) (x.Length / 2))

    let shf =
        x.Substring((int) (x.Length / 2), (int) (x.Length / 2))
        |> Seq.rev
        |> Seq.toArray
        |> System.String

    if fhf = shf then true else false


let biggestPoliProduct (range: list<int>) =
    let acc = []

    for i in range do
        for j in range do
            if isPoli (i * j) then (i * j) :: acc
            else []
    acc

biggestPoliProduct [ 1 .. 100 ]

这是一个很好的情况 list comprehension:

let biggestPoliProduct (range: list<int>) =
    [
        for i in range do
            for j in range do
                if isPoli (i * j) then
                    yield (i * j)
    ]

不需要 else 分支。