Programming Fundamentals/Loops/VB.NET: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 05:00, 8 February 2017

loops.vb

' This program displays a temperature conversion table showing Fahrenheit
' temperatures from 0 to 100, in increments of 10, and the corresponding 
' Celsius temperatures using While, For, and Do loops.

Imports System

Public Module MyProgram
    Sub Main
        WhileLoop()
        ForLoop()
        DoLoop()
    End Sub

    Private Sub WhileLoop()
        Dim F As Double
        Dim C As Double
        
        Console.WriteLine("F°    C°")
        F = 0
        While F <= 100
            C = (F - 32) * 5 / 9
            Console.WriteLine(F & " = " & C)
            F += 10
        End While
    End Sub

    Private Sub ForLoop()
        Dim F As Double
        Dim C As Double
        
        Console.WriteLine("F°    C°")
        For F = 0 To 100 Step 10
            C = (F - 32) * 5 / 9
            Console.WriteLine(F & " = " & C)
        Next
    End Sub

    Private Sub DoLoop()
        Dim F As Double
        Dim C As Double
        
        Console.WriteLine("F°    C°")
        F = 0
        Do
            C = (F - 32) * 5 / 9
            Console.WriteLine(F & " = " & C)
            F += 10
        Loop While F <= 100
    End Sub
End Module

Try It

Copy and paste the code above into one of the following free online development environments or use your own VB.NET compiler / interpreter / IDE.

See Also