Inherited from v1.0.0

return keyword

return ends a function call and yields a value back to the caller. The Bangla form ফেরত is equivalent.

Syntax

return <expression>;   // return a value
return;                // return null and exit

Examples

function add(a, b) {
    return a + b;
}

print(add(2, 3));   // 5

Early return

A bare return; exits the function and yields null. Use it as a guard:

function pay(amount) {
    if (amount <= 0) {
        print("amount must be positive");
        return;
    }
    print("paying:", amount);
}

Implicit return

If execution falls off the end of a function without return, the function returns null.

function shout(name) {
    print("HEY " + name);
    // no return — implicit null
}

print(shout("Alice"));   // prints "HEY Alice", then "null"

Returning multiple values

Bnlang has no tuple syntax. Return a list or a map:

function divmod(a, b) {
    return { q: a / b, r: a % b };
}

var r = divmod(17, 5);
print(r.q, r.r);   // 3 2

Bangla form

ফাংশন যোগ(a, b) {
    ফেরত a + b;
}