Switch
Learn switch-style branching in BornomalaScript with `dekho`, `jokhon`, and `arNahole`.
Switch
Switch-style branching is useful when you want to compare one value against several possible options.
BornomalaScript expresses this pattern with dekho, jokhon, tokhon, and arNahole.
Basic Example
Switch-style branching can be expressed using chained jokhon and tokhon blocks.
dhoro x = inputNao("Enter a value: ")
dekho (x) erModdhe {
jokhon 1 tokhon {
lekho("You typed 1")
}
jokhon 5 tokhon {
lekho("You typed 5")
}
arNahole {
lekho("Nothing Matched")
}
}
dhoro y = inputNao("Enter a number: ")
dekho (y < 2) erModdhe {
jokhon sotto tokhon {
lekho("True")
}
jokhon mittha tokhon {
lekho("False")
}
arNahole {
lekho("nothing matched")
}
}
How It Works
The switch-style block checks one expression and then compares it against several possible values.
That makes it useful when:
- a program has menu choices
- you want to match against several known values
- you want cleaner code than many separate conditions
Step-by-Step Breakdown
- The program asks the user for input
- The
dekhoblock begins - Each
jokhonblock checks one possibility - If nothing matches,
arNaholeruns
This pattern keeps decision logic easy to read.
Try These Variations
Try changing the input values and see which branch runs:
dhoro x = inputNao("Enter 1, 5, or anything else: ")
dekho (x) erModdhe {
jokhon 1 tokhon {
lekho("One")
}
jokhon 5 tokhon {
lekho("Five")
}
arNahole {
lekho("No match")
}
}
You can also try a true/false style switch example:
dhoro y = inputNao("Enter a number: ")
dekho (y < 2) erModdhe {
jokhon sotto tokhon {
lekho("True")
}
jokhon mittha tokhon {
lekho("False")
}
arNahole {
lekho("Nothing matched")
}
}
Why Switch Matters
Switch-style branching helps keep programs neat when there are many choices.
It is often easier to read than a long chain of separate conditional checks.
Common Mistakes
Beginners often make these mistakes:
- Forgetting to include
arNahole - Using the wrong comparison value
- Expecting multiple
jokhonblocks to run at the same time - Mixing input text and numeric values without checking the type
Practice Task
Try writing switch-style code for:
- A menu option
- A day of the week
- A grade or score label
- A yes/no choice
Quick Checklist
Before moving on, make sure you can:
- Use
dekhoto start a switch-style block - Add multiple
jokhonbranches - Use
arNaholefor the fallback case - Read the result of each branch correctly
If yes, you understand the basic switch pattern in BornomalaScript.