Swan Lake Beta2 is here.
import ballerina/io;

// This function definition has two parameters of type `int`. 
// `returns` clause specifies type of return value.
function add(int x, int y) returns int {

    int sum = x + y;
    // `return` statement returns a value.
    return sum;

}

public function main() {
    io:println(add(5, 11));
}

Functions

A function accepts zero or more arguments and returns a single value. Function parameters are declared as in C. You are not allowed to assign to parameters in Ballerina.

import ballerina/io;
function add(int x, int y) returns int {

This function definition has two parameters of type int. returns clause specifies type of return value.

    int sum = x + y;
    return sum;

return statement returns a value.

}
public function main() {
    io:println(add(5, 11));
}
bal run functions.bal
16
import ballerina/io;

// This function definition has two parameters of type `int`. 
// `returns` clause specifies type of return value.
function add(int x, int y) returns int {

    int sum = x + y;
    // `return` statement returns a value.
    return sum;

}

public function main() {
    io:println(add(5, 11));
}

Functions

A function accepts zero or more arguments and returns a single value. Function parameters are declared as in C. You are not allowed to assign to parameters in Ballerina.

import ballerina/io;
function add(int x, int y) returns int {

This function definition has two parameters of type int. returns clause specifies type of return value.

    int sum = x + y;
    return sum;

return statement returns a value.

}
public function main() {
    io:println(add(5, 11));
}
bal run functions.bal
16

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand