Let's now explore advance concepts. Here we come across, loops, functions, arrays, hashmaps, hashsets
Use the keyword chakra in Ganges for while loops.
Place the condition inside parentheses. The body goes inside curly braces. Statements inside the loop must also end with a semicolon (;
).
app/main.ga
1 rama count = 0;
2 chakra (count < 3) {
3 vadha("Spin the chakra");
4 count = count + 1;
5 };
Functions in Ganges are declared using the keyword kriya. You can assign a function to a variable just like any other value — functions are first-class citizens.
The kriya
block is an expression, so it can be assigned, passed around, or returned from another function.🧠 expression-based
app/main.ga
1 rama aashirvad = kriya(god) {
2 yadi (god == "vishnu") {
3 vadha("Narayana! Narayana!");
4 } anyatha {
5 vadha("Namah Parvati Patair, Har Har Mahadev!");
6 }
7 };
8 aashirvad("mahadev");
$ Terminal (zsh)
>> Namah Parvati Patair, Har Har Mahadev!
{ }
.Arrays in Ganges are created using square brackets []
. They can store multiple values in order. Access elements using zero-based indexing.
Arrays are expressions, so they can be assigned to variables, passed to functions, or returned.expression-based
app/array.ga
1 rama gods = ["vishnu", "shiva", "brahma"];
2 vadha(gods[0]);
3 vadha(gods[1]);
$ Terminal (zsh)
>> vishnu
>> shiva
[]
.0
.gods.length
(if supported) to get length. (Coming soon)Learn more:
In Ganges, hashmaps (or dictionaries) store key-value pairs. Keys are strings, and access is done via bracket notation.
Useful for fast lookups and grouping related values.
app/main.ga
1 rama gods = {
"preserver": "vishnu",
"destroyer": "shiva",
};
5 vadha(gods["preserver"]);
6 vadha(gods["destroyer"]);
$ Terminal (zsh)
>> vishnu
>> shiva
{}
and key-value pairs.gods["preserver"]
In Ganges, hashsets store **unique** values — duplicates are ignored. They are useful for fast membership checks and uniqueness guarantees.
Use hashset(...)
to declare one, and check membership using.contains(value)
.
app/main.ga
1 rama gods = hashset("vishnu", "shiva", "brahma");
3 vadha(gods.contains("shiva"));
4 vadha(gods.contains("kali"));
$ Terminal (zsh)
>> satya
>> asatya
hashset(...)
auto-removes duplicates on insert..contains(value)
returns true
or false
.Ganges Hashsets support key operations like membership checks, insertion, and deletion using the methods below.
app/main.ga
1 rama gods = hashset("shiva");
3 vadha(gods.has("shiva"));
4 gods.add("vishnu");
5 vadha(gods.has("vishnu"));
6 gods.remove("shiva");
7 vadha(gods.has("shiva"));
$ Terminal (zsh)
>> satya
>> satya
>> asatya
Checks if a value exists in the set. Returns true
or false
.
Adds a new value to the set. If it already exists, no change occurs.
Deletes a value from the set if present.