Showing posts with label F#. Show all posts
Showing posts with label F#. Show all posts

Tuesday, 13 August 2013

For loop in F#

Tutorial 2

Define list of numbers
Create for loop to display results.



Code:


// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.

open System

printfn "Started"

// define list
let list1 = [ 1; 2; 3; 4; 5; ]

//loop through all
for i in list1 do
   printfn "%d" i

// i squared
for i in list1 do
    printfn "%d squared %d" i (i*i)

printfn "Press any key to exit"
Console.ReadKey()




Your result




Hello world in F#

Lets open our VS studio and open new F# console application project.
I am writing this example based of my C# knowledge

  1. Text starting with // are comments
  2. The are no {}  as indenting does the same thing.. neeter code love it


type following

// same as using
open System

// write to screen same as Console.Write("Hello world")
printfn "Hello world"

// waits for any key to be pressed
Console.ReadKey(true)



Hit F5 and you have nice console application