Skip to main content
Skip to content

Control flow keyword

warna — else / else if

warna follows an agar block and runs when the condition was false. warna agar adds another condition to the chain.

Meaning: "otherwise"

How warna works

warna { ... } must come straight after the closing brace of an agar (a line break in between is fine). Exactly one block in an agar / warna agar / warna chain runs.

Conditions are tested from top to bottom and the first true one wins. Put the most specific check first: test marks >= 90 before marks >= 33, or every high score would stop at the broader check.

The final plain warna is optional — leave it out when nothing should happen if no condition matches.

Syntax

syntax
agar (a) {
  ...
} warna agar (b) {
  ...
} warna {
  ...
}

Runnable example

Expected output

Press Run to try it

Good afternoon

Same idea in JavaScript and Python

JavaScript
const ghante = 14;
if (ghante < 12) {
  console.log("Good morning");
} else if (ghante < 17) {
  console.log("Good afternoon");
} else {
  console.log("Good evening");
}
Python
ghante = 14
if ghante < 12:
    print("Good morning")
elif ghante < 17:
    print("Good afternoon")
else:
    print("Good evening")

Common mistakes

Writing a condition after a plain warna

warna alone takes no condition. To test another condition write warna agar (...).

Galat
agar (x > 0) { bol("+"); } warna (x < 0) { bol("-"); }
Sahi
rakho x = -2;
agar (x > 0) { bol("+"); } warna agar (x < 0) { bol("-"); } warna { bol("0"); }

Putting the broad check first

With marks >= 33 first, a 95 prints Pass and never reaches the A+ branch. Order checks from strictest to broadest.

Galat
agar (marks >= 33) { bol("Pass"); } warna agar (marks >= 90) { bol("A+"); }
Sahi
rakho marks = 95;
agar (marks >= 90) { bol("A+"); } warna agar (marks >= 33) { bol("Pass"); }

warna: frequently asked questions

Is there an elif or else-if keyword?

There is no separate keyword: write warna agar, which is warna (else) followed by a new agar (if).

Can warna be used without agar?

No. warna only makes sense as the second half of an agar statement, and the parser expects it right after an agar block.