Swan Lake Beta2 is here.
import ballerina/io;

boolean flag = true;

// Here's a conditional expression. Uses C syntax.
int n = flag ? 1 : 2;

public function main() {
    // Parentheses are options in conditions, but curly braces are required in `if/else` and other compound statements. 
    if flag {
        io:println(1);
    } else {
        io:println(2);
    }

}

Booleans and Conditionals

The boolean type has two values: true, false. The ! operator works on booleans only. && and || operators short-circuit as in C. Usual comparison operators (==, !=, <, >, <=, and >=) produce boolean values.

import ballerina/io;
boolean flag = true;
int n = flag ? 1 : 2;

Here’s a conditional expression. Uses C syntax.

public function main() {
    if flag {
        io:println(1);
    } else {
        io:println(2);
    }

Parentheses are options in conditions, but curly braces are required in if/else and other compound statements.

}
bal run booleans.bal
1
import ballerina/io;

boolean flag = true;

// Here's a conditional expression. Uses C syntax.
int n = flag ? 1 : 2;

public function main() {
    // Parentheses are options in conditions, but curly braces are required in `if/else` and other compound statements. 
    if flag {
        io:println(1);
    } else {
        io:println(2);
    }

}

Booleans and Conditionals

The boolean type has two values: true, false. The ! operator works on booleans only. && and || operators short-circuit as in C. Usual comparison operators (==, !=, <, >, <=, and >=) produce boolean values.

import ballerina/io;
boolean flag = true;
int n = flag ? 1 : 2;

Here’s a conditional expression. Uses C syntax.

public function main() {
    if flag {
        io:println(1);
    } else {
        io:println(2);
    }

Parentheses are options in conditions, but curly braces are required in if/else and other compound statements.

}
bal run booleans.bal
1

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