MOwa-Lang

Arrays

Declare, Access, and Manipulate collections of values using arrays in MowaLang.

Overview

Arrays in MowaLang let you store multiple values under a single variable. You can declare arrays with or without specifying their type. Arrays support only number, string, and bool types.

All arrays are homogeneous — meaning all elements must be of the same type. Indexing is zero-based, and accessing an invalid index will result in an error.

Array Declaration

Implicit Declaration

MowaLang will infer the type from the given values:

idhi arr1 = ["a", "b", "c"];
mowa arr1;

Explicit Declaration

Use square brackets [] to define the type and initialize values:

idhi arr2: [number] = [0, 1, 2, 3];
mowa arr2;

Accessing and Updating Array Elements

MowaLang uses zero-based indexing (just like most popular programming languages). The first element is at index 0.

idhi arr: [number] = [1, 2, 3];

mowa arr[0];     // Prints 1
arr[1] = 10;
mowa arr[1];     // Prints 10

Important

Array indexing starts strictly at 0. You cannot define custom start indexes like arr[1] = ... without declaring index 0 first. Accessing negative indexes or indexes beyond arr.length - 1 will result in an error.

Array Length

You can retrieve the size of an array using the .length property.

idhi arr = [4, 5, 6];
mowa arr.length; // Prints 3

Dynamic Arrays with User Input

You can dynamically create arrays by asking the user for the size:

idhi a: number;
mowa "Array Size ivvu mowa:";
theesko a;

idhi arr: [number(a)];
mowa a, " values enter cheyyu mowa:\n";

varaku (idhi i = 0; i < a; i++) {
  theesko arr[i];
}

mowa "Array lo unna values: ",arr;

output:

Array Size ivvu mowa:5
5 values enter cheyyu mowa:
1
2
3
4
5
Array lo unna values: [1, 2, 3, 4, 5]

Prabhas: 'Trust No-One, Kill Anyone, Be Only One'

Sort Example

pani sort(a: [number], s:number): [number] {
    varaku (idhi i = 0; i < s - 1; i++) {
        varaku (idhi j = 0; j < s - i - 1; j++) {
            okavela (a[j] > a[j + 1]) ayithe {
                idhi temp: number = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    ichey a;
}

idhi a: number;
mowa "Array Size ivvu mowa: ";
theesko a;
idhi arr: [number(a)];
mowa a, " values enter cheyyu mowa: \n";
varaku (idhi i = 0; i < a; i++) {
    theesko arr[i];
}
mowa "Array lo unna values: ",arr;

idhi sorted: [number] = sort(arr, a);
mowa "\nSorted array: ",sorted;

output:

Array Size ivvu mowa: 5 values enter cheyyu mowa:
Array lo unna values: [6, 7, 10, 67, 12]
Sorted array: [6, 7, 10, 12, 67]
AA: 'Nenu Ikkada Business loki yelu etti kelakadaaniki raale, eeleyadaaniki vachinaa..Thaggedheley'

Congratulations Mowa 🥳

You've completed the Docs section of MowaLang! 🏁
From basics to advanced concepts, you're now ready to wield MowaLang like a pro.

But wait — there's more fun ahead! Explore the Fun section next to build patterns, and unlock your creative coding side 💥.