Conditionals

Learn how to use `jodi`, `othoba`, and `nahole` for conditional logic in BornomalaScript.

Conditionals

Conditionals let your program make decisions.

Instead of always running the same code, a conditional checks a value and chooses a branch based on the result.

In BornomalaScript, jodi, othoba, and nahole are used to build this logic.

Basic Example

The example below asks for a name and age, then prints a message based on the age value:

dhoro nam = inputNao("Tomar Nam ki?: ")
dhoro age = inputNao("Tomar boyosh koto?: ")

jodi (age < 18) tahole {
    lekho("${nam} tumi vote dite parbe na")
}
othoba (age > 18) tahole {
    lekho("${nam} tumi vote dite parbe")
}
nahole {
    lekho("Tumi kichu likho nai")
}

This is a simple but powerful pattern because it allows the program to respond differently depending on the value the user enters.

How It Works

The code has three important parts:

  • jodi checks the first condition
  • othoba checks another possible condition
  • nahole runs when nothing else matches

That means your program can choose one path out of several possible paths.

Step-by-Step Breakdown

Read the example from top to bottom:

  1. The program asks the user for a name
  2. The program asks the user for an age
  3. The jodi block checks whether the age is less than 18
  4. If it is, the program prints the first message
  5. The othoba block checks whether the age is greater than 18
  6. If that is true, the program prints the second message
  7. If neither condition matches, nahole runs

This is the foundation of decision-making in programming.

Why Conditions Matter

Conditions are important because many real programs need to react to the user or to stored values.

Examples include:

  • login checks
  • age checks
  • form validation
  • menu choices
  • yes/no decisions

Without conditions, your programs would always do the same thing.

Save and Run the File

Create a file named conditionals.bs, paste the code into it, and save it.

Then run:

bs run conditionals.bs

When the program runs, it should wait for your input, then print the correct message based on the age you enter.

Important Notes

This example is easiest to understand when you test it with different ages:

  • Enter a value below 18
  • Enter a value above 18
  • Enter a value that does not match either branch

Changing the input helps you see which branch is running and why.

Common Mistakes

Beginners often make these mistakes with conditions:

  • Using the wrong variable in the comparison
  • Forgetting to close the braces
  • Mixing up jodi, othoba, and nahole
  • Using text where a number comparison is expected
  • Writing a condition that never becomes true

If the output does not look right, check the condition and the input value first.

Try These Variations

Practice with simpler checks:

dhoro age = 16
jodi (age < 18) tahole {
    lekho("Too young")
}
othoba (age > 18) tahole {
    lekho("Adult")
}
nahole {
    lekho("Same age check")
}
dhoro score = 80
jodi (score >= 50) tahole {
    lekho("Pass")
}
nahole {
    lekho("Fail")
}
dhoro loggedIn = sotto
jodi (loggedIn) tahole {
    lekho("Welcome back")
}
nahole {
    lekho("Please log in")
}

These examples show how conditions can check numbers, booleans, and other values.

Why This Lesson Matters

Conditionals are one of the most important parts of programming because they make your code feel intelligent.

They help your program decide what to do when the data changes.

Practice Task

Try writing your own conditional programs:

  1. Check whether a score is passing
  2. Check whether a person is old enough for a rule
  3. Check whether a value is true or false
  4. Show a different message if no input is provided

Quick Checklist

Before moving on, make sure you can:

  • Use jodi to check a condition
  • Use othoba for another branch
  • Use nahole for the fallback path
  • Run the file and test different inputs

If yes, you understand the basic idea of conditional logic in BornomalaScript.