Difference between procedure and function

A procedure is a block of code that can't returning a value. You can say it’s a types of function when that doesn’t return the value.

Module ABC

    Sub Main()
    End Sub
    Sub SProcedure()
    End Sub
End Module

A function is a block of code and after running its code returns a value to the calling code.

Module ABC

    Dim a As Integer = 10
    Dim b As Integer = 20
    Dim result As Integer

    Sub Main()

        result = Addition(a, b)
        Console.WriteLine(Addition(a, b))
    End Sub
    Function Addition(ByVal c As Integer, _
                       ByVal d As Integer) As Integer
        Return c+d
    End Function
End Module
Procedure are not categorize or you can say it doesn’t divide in parts.
Functions are divide in two parts
1.       Built-in function
2.       User-defined function
Use “Sub” keyword for creating procedure
Use “function” keyword for creating function.
Procedure will execute when action is called
But in case of function you can say it’s a loop.
Difference between procedure and function Difference between procedure and function Reviewed by Jacob Lefore on March 05, 2014 Rating: 5

No comments