Swan Lake Beta3 is here.
import ballerina/io;

// Modules and functions can declare variables. You can see both in this example.
// Here we declare a variable `greeting` of type `string` and initialize it to `"Hello"`.
string greeting = "Hello";

public function main() {
    // Assignments are statements not expressions.
    string name = "Ballerina";

    io:println(greeting, " ", name);
}

Variables and Types

A variable has a type, which constrains what values the variable can hold. There is a built-in set of named types, including int, float, boolean, string.

import ballerina/io;
string greeting = "Hello";

Modules and functions can declare variables. You can see both in this example. Here we declare a variable greeting of type string and initialize it to "Hello".

public function main() {
    string name = "Ballerina";

Assignments are statements not expressions.

    io:println(greeting, " ", name);
}
bal run variables_and_types.bal
Hello Ballerina
import ballerina/io;

// Modules and functions can declare variables. You can see both in this example.
// Here we declare a variable `greeting` of type `string` and initialize it to `"Hello"`.
string greeting = "Hello";

public function main() {
    // Assignments are statements not expressions.
    string name = "Ballerina";

    io:println(greeting, " ", name);
}

Variables and Types

A variable has a type, which constrains what values the variable can hold. There is a built-in set of named types, including int, float, boolean, string.

import ballerina/io;
string greeting = "Hello";

Modules and functions can declare variables. You can see both in this example. Here we declare a variable greeting of type string and initialize it to "Hello".

public function main() {
    string name = "Ballerina";

Assignments are statements not expressions.

    io:println(greeting, " ", name);
}
bal run variables_and_types.bal
Hello Ballerina
Subscribe to the newsletter

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