Basic Arrays

Learn how to create arrays and access values by index in BornomalaScript.

Basic Arrays

Arrays let you store multiple values in a single variable. They are ordered, which means each value has a position.

In BornomalaScript, you create arrays with square brackets.

Basic Example

Create arrays with square brackets and access by zero-based index.

dhoro Arr = [
    "item1", "item2", "item3",
    "item4", "item5", "item6"
]
dhoro i = 0
jotokkhon (i < 6) totokkhon {
    lekho(Arr[i])
    i++
}

This example shows two important ideas:

  • The array stores multiple items
  • The loop prints each item one by one

How It Works

Each item in the array has an index.

Indexes usually start at 0, so:

  • Arr[0] is the first item
  • Arr[1] is the second item
  • Arr[2] is the third item

That is why arrays are called ordered collections.

Step-by-Step Breakdown

  1. The array is created with six values
  2. i starts at 0
  3. The loop runs while i < 6
  4. lekho(Arr[i]) prints the current item
  5. i++ moves to the next item

This pattern is very common when working with lists of data.

Try Accessing One Item

You can also print a single item directly:

dhoro Arr = [
    "item1", "item2", "item3"
]
lekho(Arr[0])
lekho(Arr[2])

This would print the first and third items.

Common Mistakes

Beginners often make these mistakes with arrays:

  • Forgetting that indexes start at zero
  • Trying to access an item that does not exist
  • Mixing up array names and variable names
  • Forgetting that the loop must stop before the array ends

Practice Task

Try writing an array that stores:

  1. Your name
  2. Your city
  3. Your school subject
  4. Your favorite color

Then print each item one by one.

Quick Checklist

Before moving on, make sure you can:

  • Create an array
  • Read items by index
  • Print all values using a loop
  • Remember that the first item is at index 0

If yes, you are ready for nested arrays.