import ballerina/io;

public function main() {
    int a = 10;
    int b = 0;

    // This is a basic `if` statement.
    if (a == 10) {
        io:println("a == 10");
    }

    // This is an `if-else` scenario.
    if (a < b) {
        io:println("a < b");
    } else {
        io:println("a >= b");
    }

    // This is an `if-else-if-else` scenario.
    if (b < 0) {
        io:println("b < 0");
    } else if (b > 0) {
        io:println("b > 0");
    } else {
        io:println("b == 0");
    }
}

If/Else

An if statement provides a way to perform conditional execution.

import ballerina/io;
public function main() {
    int a = 10;
    int b = 0;
    if (a == 10) {
        io:println("a == 10");
    }

This is a basic if statement.

    if (a < b) {
        io:println("a < b");
    } else {
        io:println("a >= b");
    }

This is an if-else scenario.

    if (b < 0) {
        io:println("b < 0");
    } else if (b > 0) {
        io:println("b > 0");
    } else {
        io:println("b == 0");
    }
}

This is an if-else-if-else scenario.

# To run this sample, navigate to the directory that contains the
# `.bal` file, and execute the `ballerina run` command below.
ballerina run if_else.bal
a == 10
a >= b
b == 0