Skip to main content
Skip to content

Control flow keyword

agar — if

agar runs a block of code only when its condition is truthy. Pair it with warna to handle the other case.

Meaning: "if"

How agar works

Write agar, a condition in brackets and a block in curly braces. The braces are required even for one line. The brackets are recommended — they make the condition's start and end obvious.

The condition does not have to be a real sahi/galat: galat, khali, 0 and the empty string count as false, everything else (including an empty list) counts as true.

Comparisons use ==, !=, <, >, <= and >=, and can be combined with &&, || and !. == is strict, so a number never equals text.

Syntax

syntax
agar (condition) {
  // runs when condition is truthy
}

Runnable example

Expected output

Press Run to try it

Order ho gaya!Bacha balance: 51

Same idea in JavaScript and Python

JavaScript
let balance = 250;
const price = 199;
if (balance >= price) {
  console.log("Order ho gaya!");
  balance = balance - price;
}
Python
balance = 250
price = 199
if balance >= price:
    print("Order ho gaya!")
    balance = balance - price

Common mistakes

Using = instead of ==

A single = stores a value; it does not compare. Inside a condition always use == to ask "is it equal?".

Galat
rakho x = 3;
agar (x = 5) { bol("paanch"); }
Sahi
rakho x = 3;
agar (x == 5) { bol("paanch"); } warna { bol("paanch nahi"); }

Comparing text with a number

"5" == 5 is galat because the types differ. Input from pucho() is always text — convert it with sankhya() first.

Galat
agar ("5" == 5) { bol("barabar"); }
Sahi
agar (sankhya("5") == 5) { bol("barabar"); }

Leaving out the braces

Unlike some languages, AltFLang always needs { } after the condition.

Galat
agar (sahi) bol("hi");
Sahi
agar (sahi) { bol("hi"); }

agar: frequently asked questions

How do I write if-else in Hindi programming with AltFLang?

Use agar for if and warna for else: agar (marks >= 33) { bol("Pass"); } warna { bol("Fail"); }. For more branches, chain warna agar.

Are the brackets around the condition required?

The curly braces around the block are required. The round brackets around the condition are optional in the current parser, but writing them is strongly recommended for readability.