Different Types of For Loops in F#


This content was proof-read by Grammarly. You can Try Grammary for FREE

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
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: