Different Types of For Loops in F#

Published on August 10, 2014 by abundantcode

Filed under F#

Last modified August 10, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3571 times

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to convert Nullable int to integer in C# ?

You can convert the Nullable Integer to Integer in C# using one of the below methods. 1. Using null...

FSharp Interactive Commands

FSharp Interactive UI includes few good number of commands which can be used by the F# Developers . ...

#time switch to measure the execution time in F#

If you want to measure the execution time of your F# code , you can use the #time attribute which le...