Getting Started
Quick Start Guide
Write your first BanglaCode program in 5 minutes. This guide covers the essential syntax to get you started.
Your First Program
Create a file called hello.bang and add the following code:
hello.bangbanglacode
| 1 | // Your first BanglaCode program! |
| 2 | dekho("Namaskar, BanglaCode!"); |
| 3 | |
| 4 | // Variables |
| 5 | dhoro naam = "World"; |
| 6 | dekho("Hello,", naam); |
Run it with:
./banglacode hello.bangOutput:
Namaskar, BanglaCode!
Hello, WorldVariables
Use dhoro (meaning "hold") to declare variables. BanglaCode is dynamically typed.
| 1 | // Numbers |
| 2 | dhoro age = 25; |
| 3 | dhoro pi = 3.14159; |
| 4 | |
| 5 | // Strings |
| 6 | dhoro name = "Rahim"; |
| 7 | dhoro greeting = 'Namaskar'; |
| 8 | |
| 9 | // Booleans |
| 10 | dhoro isStudent = sotti; // true |
| 11 | dhoro isWorking = mittha; // false |
| 12 | |
| 13 | // Null |
| 14 | dhoro data = khali; // null |
| 15 | |
| 16 | // Arrays |
| 17 | dhoro numbers = [1, 2, 3, 4, 5]; |
| 18 | dhoro mixed = ["hello", 42, sotti]; |
| 19 | |
| 20 | // Maps (objects) |
| 21 | dhoro person = { |
| 22 | naam: "Ankan", |
| 23 | boyosh: 25, |
| 24 | city: "Kolkata" |
| 25 | }; |
Basic Operations
| 1 | // Arithmetic |
| 2 | dhoro sum = 10 + 5; // 15 |
| 3 | dhoro diff = 10 - 5; // 5 |
| 4 | dhoro prod = 10 * 5; // 50 |
| 5 | dhoro quot = 10 / 5; // 2 |
| 6 | dhoro rem = 10 % 3; // 1 |
| 7 | dhoro power = 2 ** 3; // 8 |
| 8 | |
| 9 | // String concatenation |
| 10 | dhoro fullName = "Rahim" + " " + "Khan"; |
| 11 | |
| 12 | // Comparison |
| 13 | dhoro isEqual = 5 == 5; // sotti |
| 14 | dhoro isGreater = 10 > 5; // sotti |
| 15 | |
| 16 | // Logical operators |
| 17 | dhoro result = sotti ebong mittha; // and -> mittha |
| 18 | dhoro result2 = sotti ba mittha; // or -> sotti |
| 19 | dhoro result3 = na sotti; // not -> mittha |
Conditionals
Use jodi (if) and nahole (else) for conditional statements:
| 1 | dhoro score = 85; |
| 2 | |
| 3 | jodi (score >= 90) { |
| 4 | dekho("Grade: A"); |
| 5 | } nahole jodi (score >= 80) { |
| 6 | dekho("Grade: B"); |
| 7 | } nahole jodi (score >= 70) { |
| 8 | dekho("Grade: C"); |
| 9 | } nahole { |
| 10 | dekho("Grade: F"); |
| 11 | } |
Loops
While Loop
Use jotokkhon (while) for while loops:
| 1 | dhoro i = 0; |
| 2 | jotokkhon (i < 5) { |
| 3 | dekho("Count:", i); |
| 4 | i = i + 1; |
| 5 | } |
For Loop
Use ghuriye (rotating/looping) for for loops:
| 1 | ghuriye (dhoro i = 1; i <= 5; i = i + 1) { |
| 2 | dekho("Number:", i); |
| 3 | } |
Functions
Use kaj (work/function) to define functions and ferao (return) to return values:
| 1 | // Simple function |
| 2 | kaj greet(naam) { |
| 3 | dekho("Namaskar,", naam); |
| 4 | } |
| 5 | |
| 6 | greet("Rahim"); // Namaskar, Rahim |
| 7 | |
| 8 | // Function with return value |
| 9 | kaj add(a, b) { |
| 10 | ferao a + b; |
| 11 | } |
| 12 | |
| 13 | dhoro result = add(5, 3); |
| 14 | dekho("Sum:", result); // Sum: 8 |
| 15 | |
| 16 | // Recursive function |
| 17 | kaj factorial(n) { |
| 18 | jodi (n <= 1) { |
| 19 | ferao 1; |
| 20 | } |
| 21 | ferao n * factorial(n - 1); |
| 22 | } |
| 23 | |
| 24 | dekho("5! =", factorial(5)); // 5! = 120 |
Classes
Use sreni (class) to define classes and notun (new) to create instances:
| 1 | sreni Person { |
| 2 | // Constructor |
| 3 | shuru(naam, boyosh) { |
| 4 | ei.naam = naam; |
| 5 | ei.boyosh = boyosh; |
| 6 | } |
| 7 | |
| 8 | // Method |
| 9 | kaj introduce() { |
| 10 | dekho("Hi, I am", ei.naam, "and I am", ei.boyosh, "years old"); |
| 11 | } |
| 12 | |
| 13 | kaj birthday() { |
| 14 | ei.boyosh = ei.boyosh + 1; |
| 15 | dekho(ei.naam, "is now", ei.boyosh); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | // Create instance |
| 20 | dhoro person = notun Person("Ankan", 25); |
| 21 | person.introduce(); // Hi, I am Ankan and I am 25 years old |
| 22 | person.birthday(); // Ankan is now 26 |
Error Handling
Use chesta (try), dhoro_bhul (catch error), and felo (throw):
| 1 | chesta { |
| 2 | dhoro result = 10 / 0; |
| 3 | } dhoro_bhul (error) { |
| 4 | dekho("Error occurred:", error); |
| 5 | } shesh { |
| 6 | dekho("Cleanup complete"); |
| 7 | } |
| 8 | |
| 9 | // Throw custom error |
| 10 | kaj validateAge(age) { |
| 11 | jodi (age < 0) { |
| 12 | felo "Age cannot be negative"; |
| 13 | } |
| 14 | ferao sotti; |
| 15 | } |
Built-in Functions
BanglaCode comes with 95+ built-in functions:
| 1 | // Output |
| 2 | dekho("Hello World"); |
| 3 | |
| 4 | // Type checking |
| 5 | dekho(dhoron(42)); // "int" |
| 6 | dekho(dhoron("hello")); // "string" |
| 7 | |
| 8 | // String operations |
| 9 | dekho(dorghyo("hello")); // 5 |
| 10 | dekho(boroHater("hello")); // "HELLO" |
| 11 | dekho(chotoHater("HELLO")); // "hello" |
| 12 | |
| 13 | // Array operations |
| 14 | dhoro arr = [3, 1, 4, 1, 5]; |
| 15 | dhokao(arr, 9); // Push |
| 16 | dekho(dorghyo(arr)); // 6 |
| 17 | dekho(saja(arr)); // [1, 1, 3, 4, 5, 9] |
| 18 | |
| 19 | // Math |
| 20 | dekho(borgomul(16)); // 4 (square root) |
| 21 | dekho(niratek(-5)); // 5 (absolute value) |
| 22 | dekho(kache(3.7)); // 4 (round) |
Next Steps
You now know the basics! Explore the documentation to learn more about: