# Fibonacci Sequence (>= .net 4.0)

Page 1 of 1

## 2 Replies - 1981 Views - Last Post: 07 October 2014 - 01:29 PM

• MrCupOfT

Reputation: 2294
• Posts: 9,531
• Joined: 29-May 08

# Fibonacci Sequence (>= .net 4.0)

Posted 23 March 2014 - 01:08 PM

Requires a reference to Framework Assembly System.Numerics

```Imports System.Numerics

Public Module Numerics

Public Iterator Function FibonacciSeq() As IEnumerable(of BigInteger)
Dim n = { BigInteger.Zero, BigInteger.One }
While True
Yield n(0)
n = {n(1),n(0) + n(1) }
End While
End Function

End Module

```

Example2

```Dim ListOfTheFirst1000 = FibonacciSeq.Take(1000).ToList

Dim Euler2 = FibonacciSeq.TakeWhile(Function(x) x < 4000000).Where(Function(x) x.IsEven).Sum

```

The Euler2 result relies on the following additional extension method.

Spoiler

Is This A Good Question/Topic? 0

## Replies To: Fibonacci Sequence (>= .net 4.0)

### #2 ImpishTendencies

Reputation: 0
• Posts: 3
• Joined: 06-October 14

## Re: Fibonacci Sequence (>= .net 4.0)

Posted 07 October 2014 - 01:19 PM

Hey Im trying to code Fibonacci as a loop in VB 2008 Express edition and the term 'Yield' isn't appearing in blue. Do you have any suggestions as to what I can do. (I've copied from your first example mind you)

• MrCupOfT

Reputation: 2294
• Posts: 9,531
• Joined: 29-May 08

## Re: Fibonacci Sequence (>= .net 4.0)

Posted 07 October 2014 - 01:29 PM

Iterators Tutorial
For the loop version isn't that hard, go and think about it.

This post has been edited by AdamSpeight2008: 07 October 2014 - 01:30 PM