F#zzBuzz: Learning the easy way So I made a quick programme in F# to do FizzBuzz, I'm trying to learn more languages, so I figured I'd do something functional for a change. (Haskell is also on the list.)

FizzBuzz is pretty self-explanatory: every third value print Fizz, every fifth print Buzz (possible both if it's a multiple of 3 and 5).

[&lt;EntryPoint&gt;]
let main argv = 
    let fizzBuzzSequence = seq {
        for value in 1..100 do
            let valueMod3 = value % 3
            let valueMod5 = value % 5

            if valueMod3 = 0 &amp;&amp; valueMod5 = 0 then yield "FizzBuzz"
            else if valueMod3 = 0 &amp;&amp; valueMod5 &lt;&gt; 0 then yield "Fizz"
            else if valueMod3 &lt;&gt; 0 &amp;&amp; valueMod5 = 0 then yield "Buzz"
            else yield value.ToString()
    }
    for value in fizzBuzzSequence do printfn "%s" value
    0
First off, I don't see a real need for these two variables:


let valueMod3 = value % 3
let valueMod5 = value % 5



To me, they just seem a little unnecessary. In fact, writing out the expression value % 3 or value % 5 takes the exact same amount of keystrokes as writing valueMod3 or valueMod5.

Next, I'd highly recommend that you get into the habit of using Match Expressions rather than plain old if statements, as it's more functional, and will give you more benefits, like Pattern matching, over if statements. This means that this small chunk of if statements:


if valueMod3 = 0 &amp;&amp; valueMod5 = 0 then yield "FizzBuzz"
else if valueMod3 = 0 &amp;&amp; valueMod5 &lt;&gt; 0 then yield "Fizz"
else if valueMod3 &lt;&gt; 0 &amp;&amp; valueMod5 = 0 then yield "Buzz"
else yield value.ToString()



Would become a Match Expression, like this:

match n with
| n when n % 3 = 0 &amp;&amp; n % 5 = 0 -&gt; yield "FizzBuzz"
| n when n % 3 = 0 -&gt; yield "Fizz"
| n when n % 5 = 0 -&gt; yield "Buzz"
| _ -&gt; yield n.ToString()


After all these improvements to your code, I ended up with the following, working code:

let fizzbuzzSequence = seq { 
    for n in 1 .. 100 do
        match n with
        | n when n % 3 = 0 &amp;&amp; n % 5 = 0 -&gt; yield "FizzBuzz"
        | n when n % 3 = 0 -&gt; yield "Fizz"
        | n when n % 5 = 0 -&gt; yield "Buzz"
        | _ -&gt; yield n.ToString()
}

[&lt;EntryPoint&gt;]
let main argv = 
    for item in fizzbuzzSequence do
        System.Console.WriteLine(item)

    0