F# supports 3 different types of For Loops . These include
- For…to – This is astandard for loop
- For .. In – This is similar to For Each in C#
- for…downto
Different Types of For Loops in F#
Below is a code snippet demonstrating the different For Loops in F#
// AbundantCode F# Tutorials and Code snippets open System [<EntryPoint>] let main argv = // For Loops in F# for indexer = 10 to 50 do Console.WriteLine(indexer) for indexer = 50 downto 10 do Console.WriteLine(indexer) for indexer in [10..50] do Console.WriteLine(indexer) let retval = Console.ReadLine() 0 // return an integer exit code
Leave a Reply