Inherited from v1.0.0

else keyword

else attaches a fallback branch to an if. The Bangla form নাহলে is equivalent.

else always follows an if; it never stands on its own. For multi-way branching, chain else if.

Syntax

if (<condition>) {
    // primary branch
} else {
    // runs when the condition was false
}

Examples

var is_admin = false;

if (is_admin) {
    print("welcome, admin");
} else {
    print("guest access");
}

Bangla:

চলক is_admin = false;

যদি (is_admin) {
    print("welcome, admin");
} নাহলে {
    print("guest access");
}

Chained else if

var status_code = 404;

if (status_code == 200) {
    print("ok");
} else if (status_code == 404) {
    print("not found");
} else if (status_code >= 500) {
    print("server error");
} else {
    print("other:", status_code);
}

See also

  • if — the primary branch.