Arrays & Real-World Examples
From single values to collections
So far, we’ve worked with single pieces of data:
-
One name
-
One number
-
One decision
But real life is rarely that simple.
We don’t have one friend — we have many.
We don’t store one task — we manage lists.
We don’t process one item — we process collections.
This is where arrays come in.
1. Arrays – Keeping many things together
An array is simply a list of values stored under one name.
In GTLang, arrays are written using square brackets [].
A simple array
Read it like this:
“Fruits is a list containing Apple, Banana, and Orange.”
That’s it.
No special keywords.
No strict types.
Just data.
Accessing array elements
Arrays start counting from 0.
Output:
Modifying an array
Output:
You can change data anytime.
Nothing is locked.
Adding new elements
Now the list grows naturally — just like real life.
2. Looping through arrays (the natural way)
Arrays become powerful when combined with loops.
Printing all items
Output:
Here:
-
$_valuemeans “the current item” -
You don’t need indexes unless you want them
With index and value
Output:
Clean. Predictable. Easy to read.
3. Real example #1 – A simple todo list
Let’s build something useful.
Step 1: Create tasks
Step 2: Show tasks
Output:
This is already a real program.
4. Arrays with mixed data (because life is mixed)
GTLang does not force everything to be the same type.
This array contains:
-
A string
-
A number
-
A boolean
That flexibility makes GTLang very beginner-friendly
GREENTEA-PROGRAMMING-LANGUAGE-M…
5. Real example #2 – Finding data in a list
Let’s search for a name.
Output:
This is a classic beginner task, and GTLang makes it readable instead of scary.
6. Nested arrays – Data inside data
Sometimes, data has structure.
Example: students and their scores.
Loop through them:
Output:
You are now working with structured data.
7. Real example #3 – Simple grading system
Output:
This is real logic, not just syntax practice.
8. Why arrays matter
Arrays allow you to:
-
Handle multiple values
-
Build real programs
-
Represent real-world data
-
Think in structures, not lines
Once you understand arrays, programming stops feeling like typing —
it starts feeling like designing ideas.
Final thoughts – You’re building real programs now
At this point, you can:
-
Store data
-
Group data
-
Loop through data
-
Make decisions
-
Build small systems
That is not “just learning”.
That is programming.
GTLang simply removes unnecessary barriers so you can focus on thinking, not syntax.
In the next part, you can explore:
-
Objects and simple classes
-
Working with files
-
Small automation scripts
-
Turning ideas into tools
Slowly. Calmly.
Like green tea ☕🌱
