if keyword
if runs a block when its condition evaluates to true. Chain with else if and else for additional branches. The Bangla form যদি is exactly equivalent.
Syntax
if (<condition>) {
// runs when condition is true
} else if (<another condition>) {
// runs when the first was false and this is true
} else {
// runs when nothing above matched
}
Examples
var score = 85;
if (score >= 80) {
print("Grade: A+");
} else if (score >= 70) {
print("Grade: A");
} else {
print("Grade: below A");
}
Bangla form:
চলক নম্বর = 85;
যদি (নম্বর >= 80) {
print("গ্রেড: A+");
} নাহলে যদি (নম্বর >= 70) {
print("গ্রেড: A");
} নাহলে {
print("গ্রেড: A-এর নিচে");
}
Truthiness
Bnlang has no JavaScript-style truthiness rules. A condition must evaluate to a boolean (true / false). Compare explicitly:
var name = "";
// Correct:
if (name == "") { print("empty"); }
// Wrong — does not coerce string to boolean:
// if (name) { ... }
Early return idiom
For functions, prefer early returns over deeply nested if:
function pay(amount) {
if (amount <= 0) {
print("amount must be positive");
return;
}
print("processing payment:", amount);
}