Declaring Variables
Learn how to declare variables in BornomalaScript using `dhoro`, then print and reuse values with `lekho`.
Variables
Variables let you store information so you can use it later in your program. Instead of writing the same value many times, you give it a name and reuse that name whenever you need it.
In BornomalaScript, the dhoro keyword is used to declare a variable.
Basic Example
Declare variables with dhoro and print with lekho:
dhoro number = 10 // number is a variable whose value is 10
lekho(number) // prints 10
This example stores the number 10 in a variable named number.
When you print number, BornomalaScript uses the value that was stored earlier.
How It Works
The declaration has two parts:
dhorotells BornomalaScript to create a variablenumber = 10gives that variable its initial value
After the variable is created, you can print it with lekho(number).
That means variables help you:
- store data
- reuse values
- make programs easier to read
- avoid repeating the same number or text many times
Why Variable Names Matter
Use meaningful names so you can understand your code later.
For example, number is fine in a simple lesson, but in a real program you may want names that describe the value more clearly.
Good names make your program easier to maintain and easier for other people to read.
String Example
You can also store text in a variable:
dhoro nam = "Mahfuz"
lekho("Shagotom, " + nam) // prints Shagotom, Mahfuz
Here, the variable nam stores text instead of a number.
The + sign combines the greeting text with the variable value so both parts appear in the final output.
Step-by-Step Breakdown
If you are new to programming, read the example one line at a time:
dhoro nam = "Mahfuz"creates a variable namednam- The variable stores the text
Mahfuz lekho("Shagotom, " + nam)prints the greeting plus the stored name- The terminal shows
Shagotom, Mahfuz
This pattern is one of the most common things you will do in programming.
Save and Run the File
Create a file named variables.bs, paste the example code into it, and save it.
Then run:
bs run variables.bs
If everything is correct, the output should appear in your terminal.
Try These Variations
Once the basic example works, change the values and test again:
dhoro age = 20
lekho(age)
dhoro basha = "Dhaka"
lekho("Ami " + basha + " theke eshechi")
dhoro subject = "Bangla"
lekho("Amar pochondo subject: " + subject)
Changing the value helps you understand that the variable name stays the same while the stored data can change.
Good Practices
When you create variables, follow these habits:
- Choose clear and descriptive names
- Use one meaning per variable
- Keep text values inside quotes
- Reuse the variable instead of typing the value again and again
- Test your code after each change
Good variable naming becomes very important as your programs grow larger.
Common Mistakes
Beginners often make a few common mistakes with variables:
- Forgetting to write
dhoro - Forgetting the
=sign - Using a value before it is declared
- Typing the variable name differently in the print line
- Forgetting quotation marks around text values
If the code does not work, check the variable name carefully. Even a small spelling difference can cause a problem.
Practice Task
Try writing your own variable examples:
- Store your age in a variable and print it
- Store your name and print a greeting
- Store your city name and print a sentence about where you live
- Store your favorite subject and print it in a sentence
Example:
dhoro name = "Mahfuz"
lekho("Amar nam " + name)
Why This Lesson Matters
Variables are one of the most important parts of programming because almost every real program needs to store information.
Once you understand variables, you can start building programs that remember values, calculate results, and react to user input.
Quick Checklist
Before moving to the next lesson, make sure you can answer yes to these questions:
- Can you declare a variable with
dhoro? - Can you print the variable with
lekho? - Can you store both numbers and text?
- Can you change the value and run the program again?
If yes, you are ready for the next basics topic.
Next Step
After variables, the next useful lesson is input and output. That will show you how to read data from the user and print more dynamic results.