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!
2dekho("Namaskar, BanglaCode!");
3
4// Variables
5dhoro naam = "World";
6dekho("Hello,", naam);

Run it with:

./banglacode hello.bang

Output:

Namaskar, BanglaCode!
Hello, World

Variables

Use dhoro (meaning "hold") to declare variables. BanglaCode is dynamically typed.

1// Numbers
2dhoro age = 25;
3dhoro pi = 3.14159;
4
5// Strings
6dhoro name = "Rahim";
7dhoro greeting = 'Namaskar';
8
9// Booleans
10dhoro isStudent = sotti; // true
11dhoro isWorking = mittha; // false
12
13// Null
14dhoro data = khali; // null
15
16// Arrays
17dhoro numbers = [1, 2, 3, 4, 5];
18dhoro mixed = ["hello", 42, sotti];
19
20// Maps (objects)
21dhoro person = {
22 naam: "Ankan",
23 boyosh: 25,
24 city: "Kolkata"
25};

Basic Operations

1// Arithmetic
2dhoro sum = 10 + 5; // 15
3dhoro diff = 10 - 5; // 5
4dhoro prod = 10 * 5; // 50
5dhoro quot = 10 / 5; // 2
6dhoro rem = 10 % 3; // 1
7dhoro power = 2 ** 3; // 8
8
9// String concatenation
10dhoro fullName = "Rahim" + " " + "Khan";
11
12// Comparison
13dhoro isEqual = 5 == 5; // sotti
14dhoro isGreater = 10 > 5; // sotti
15
16// Logical operators
17dhoro result = sotti ebong mittha; // and -> mittha
18dhoro result2 = sotti ba mittha; // or -> sotti
19dhoro result3 = na sotti; // not -> mittha

Conditionals

Use jodi (if) and nahole (else) for conditional statements:

1dhoro score = 85;
2
3jodi (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:

1dhoro i = 0;
2jotokkhon (i < 5) {
3 dekho("Count:", i);
4 i = i + 1;
5}

For Loop

Use ghuriye (rotating/looping) for for loops:

1ghuriye (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
2kaj greet(naam) {
3 dekho("Namaskar,", naam);
4}
5
6greet("Rahim"); // Namaskar, Rahim
7
8// Function with return value
9kaj add(a, b) {
10 ferao a + b;
11}
12
13dhoro result = add(5, 3);
14dekho("Sum:", result); // Sum: 8
15
16// Recursive function
17kaj factorial(n) {
18 jodi (n <= 1) {
19 ferao 1;
20 }
21 ferao n * factorial(n - 1);
22}
23
24dekho("5! =", factorial(5)); // 5! = 120

Classes

Use sreni (class) to define classes and notun (new) to create instances:

1sreni 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
20dhoro person = notun Person("Ankan", 25);
21person.introduce(); // Hi, I am Ankan and I am 25 years old
22person.birthday(); // Ankan is now 26

Error Handling

Use chesta (try), dhoro_bhul (catch error), and felo (throw):

1chesta {
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
10kaj 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
2dekho("Hello World");
3
4// Type checking
5dekho(dhoron(42)); // "int"
6dekho(dhoron("hello")); // "string"
7
8// String operations
9dekho(dorghyo("hello")); // 5
10dekho(boroHater("hello")); // "HELLO"
11dekho(chotoHater("HELLO")); // "hello"
12
13// Array operations
14dhoro arr = [3, 1, 4, 1, 5];
15dhokao(arr, 9); // Push
16dekho(dorghyo(arr)); // 6
17dekho(saja(arr)); // [1, 1, 3, 4, 5, 9]
18
19// Math
20dekho(borgomul(16)); // 4 (square root)
21dekho(niratek(-5)); // 5 (absolute value)
22dekho(kache(3.7)); // 4 (round)

Next Steps

You now know the basics! Explore the documentation to learn more about: