Creating list ranges in F#

We can easily create a list of integers in F# with a start and end value as follows:

let myRangeList = [1..10]

myRangeList will contain the integers from 1 to 10:

int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]

We can also add a step parameter in the middle to increment the values by some number:

let myRangeList = [1..3..10]

myRangeList will contain the values [1; 4; 7; 10].

If the step variable is 2 then the last element in the list will be 9 since 11 is more than the top value 10:

let myRangeList = [1..2..10]

int list = [1; 3; 5; 7; 9]

We can also create a list of floats:

let myFloatList = [2. ..0.3 .. 8.]

myFloatList will contain the following elements:

float list =
[2.0; 2.3; 2.6; 2.9; 3.2; 3.5; 3.8; 4.1; 4.4; 4.7; 5.0; 5.3; 5.6; 5.9; 6.2;
6.5; 6.8; 7.1; 7.4; 7.7; 8.0]

View all F# related articles here.

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


A great site

Elliot Balynn's Blog

A directory of wonderful thoughts

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog


Once Upon a Camayoc

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: