Functions

Sat 09 February 2019, in category Procedures and Functions

function, procedure

A function is a block of code consisting of a group of statements that usually return a value. Additionally, logic can be encapsulated within a function to allow easier testing and consistency in the application. Here are various examples that show how to calculate the area of rectangle.

Java

private int calculateArea(int length, int width)
{
    return length * width;
}

C#

private int calculateArea(int length, int width)
{
    return length * width;
}

Python

def calculateArea(length, width):
    return length * width

JavaScript

function calculateArea(length, width)
{
    return length * width;
}

Go

func calculateArea(length int, width int){
    return length * width
}