Welcome to collectivesolver - Programming & Software Q&A with Examples. A website you can trust. All programs tested and work.

Contact: aviboots(AT)netvision.net.il


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Dental Dog Chews
FRESH BREATHIES

GlucoTrust is a brand new, science-backed supplement that supports healthy blood sugar levels AND weight loss for men and women

Everything you need to sell anywhere

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
100%

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

24,887 questions

32,502 answers

573 users

How to use yield to return multiple elements from a function one at a time in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Iterator Function Get_Fibonacci_Sequence(ByVal total As Integer) As IEnumerable(Of Integer)
        Dim returnValue As Integer = 1, prev As Integer = 0

        For i As Integer = 0 To total - 1
            Yield returnValue
            Dim temp As Integer = returnValue
            returnValue = prev + returnValue
            prev = temp
        Next
    End Function

    Public Shared Sub Main()
        For Each i As Integer In Get_Fibonacci_Sequence(11)
            Console.Write("{0} ", i)
        Next
    End Sub
End Class




' run:
'
' 1 1 2 3 5 8 13 21 34 55 89
'

 




answered 4 days ago by avibootz
...