Logical Operators
Learn how to combine conditions with AND and OR in BornomalaScript using `&&` and `||`.
Logical Operators
Logical operators let you combine multiple conditions into one decision.
That is useful when your program needs more than one rule to be true before it should run a block of code.
BornomalaScript uses familiar boolean-style logic with && and ||.
What You Will Learn
In this lesson, you will learn how to:
- combine two conditions with AND
- allow one condition out of many with OR
- use logical operators inside
jodiblocks - write cleaner decision-making code
Basic Example
Logical operations work as you expect:
dhoro a = sotto
dhoro b = mittha
jodi (a && b) tahole {
lekho("both true")
} othoba (a || b) tahole {
lekho("at least one true")
} nahole {
lekho("both false")
}
This example shows two common logical checks:
&&means both sides must be true||means at least one side must be true
How It Works
Logical operators are used when a single condition is not enough.
For example:
- a student may need to be old enough and enrolled
- a user may need to be logged in or have permission
- a form may need two fields filled before it can continue
That means logical operators help you combine rules instead of writing many separate checks.
AND with &&
The AND operator is used when both conditions must be true.
Example:
dhoro age = 20
dhoro hasPermission = sotto
jodi (age >= 18 && hasPermission) tahole {
lekho("Access granted")
} nahole {
lekho("Access denied")
}
In this case, the program only grants access if both parts are true.
OR with ||
The OR operator is used when at least one condition is enough.
Example:
dhoro isTeacher = mittha
dhoro isStudent = sotto
jodi (isTeacher || isStudent) tahole {
lekho("You can enter")
} nahole {
lekho("You cannot enter")
}
Here, the program continues if either value is true.
Step-by-Step Breakdown
Read the first example carefully:
- Two boolean values are created
- The program checks whether both values are true with
&& - If that fails, it checks whether at least one value is true with
|| - If neither branch matches,
naholeruns
This is the same decision-making style you use in real programs.
Why Logical Operators Matter
Logical operators help you write conditions that are more realistic.
Instead of checking one rule at a time, you can combine rules into a single expression.
That is useful for:
- permissions
- login checks
- validation rules
- menu logic
- simple access control
Important Notes
When you combine conditions, order matters.
If your expression is long, test it one piece at a time before combining everything into a single condition.
That makes debugging much easier.
Try These Variations
Practice with your own examples:
dhoro loggedIn = sotto
dhoro hasToken = mittha
jodi (loggedIn && hasToken) tahole {
lekho("Secure access")
} nahole {
lekho("Need more checks")
}
dhoro rainy = mittha
dhoro holiday = sotto
jodi (rainy || holiday) tahole {
lekho("Stay home")
} nahole {
lekho("Go outside")
}
dhoro isAdmin = sotto
dhoro isOwner = mittha
jodi (isAdmin || isOwner) tahole {
lekho("Allowed")
} nahole {
lekho("Denied")
}
Common Mistakes
Beginners often make these mistakes:
- using
&&when||was needed - forgetting to make both sides boolean values
- trying to combine conditions without testing them first
- assuming both sides of
||must be true
If the result looks wrong, check which logical operator you used.
Practice Task
Try writing programs that:
- allow access only when two conditions are true
- allow access when either one of two conditions is true
- print a different message when both are false
Quick Checklist
Before moving on, make sure you can:
- use
&&for AND logic - use
||for OR logic - place logical operators inside a condition
- understand when a branch should run
If yes, you understand the basics of logical operators in BornomalaScript.