Lists
A list, also known as an array, is a collection of multiple values stored in a single variable. It is one of the most useful structures in programming, allowing you to store, access, update, and manipulate a group of data efficiently.
Methods to Access Array Functions
There are three main ways to perform operations on lists in EasyBite:
S/N | Access Type | Example | Description |
---|---|---|---|
1 | Dot Notation | items.length() | Access built-in functions directly from the list variable |
2 | Module-Based | array.remove(items, "apple") | Use functions through the full array module |
3 | Shorthand Import (Preferred) | import remove, append from array then remove(items, "apple") | Import only the specific functions you want to use |
Why Use Lists?
- Store multiple values under one name
- Access items by position
- Perform batch operations easily (like looping)
- Useful for working with tables, forms, data, and more
- Supports any type of data, including mixed types
Declaring and Initializing a List
declare mixed[]
set mixed to ["Ali", 21, true, 99.5]
declare mixed[]
: Creates an empty list namedmixed
set mixed to [...]
: Initializes it with values of different types
You can store strings, numbers, booleans, or any combination.
Accessing List Elements
show(mixed[0]) // "Ali"
show(mixed[1]) // 21
show(mixed[2]) // true
- Lists are zero-indexed, meaning the first item is at position
0
- You can access any element using its index inside square brackets
Accessing Nested Arrays Without a Loop
declare matrix[]
set matrix to [[1, 2], [3, 4], [5, 6]]
show(matrix[0][1]) // 2
show(matrix[2][0]) // 5
- You can store arrays inside arrays (2D structure)
- Use double index to get specific rows and columns like a table
Getting the Length of a List
declare names[]
set names to ["Ali", "Fatima", "Zainab"]
// Method 1: Dot Notation
show(names.length())
// Method 2: Import length function
import length from array
show(length(names))
// Method 3: Full array module
import array
show(array.length(names))
- Use
.length()
or thelength()
function to count items in a list - Works with both built-in and imported function formats
Looping Through Lists
Foreach Loop – Best for Reading
foreach name in names
show(name)
end foreach
- Loops through each value one by one
- Best when you only need the value, not the index
For Loop – Best for Indexing
for i from 0 to names.length() - 1
show(names[i])
end for
- Loops using index numbers
- Useful when you want to modify values or use the position
Modifying Lists with Imported Functions
import remove, append from array
declare fruits[]
set fruits to ["apple", "banana", "mango"]
append(fruits, "grape") // Adds at the end
remove(fruits, "banana") // Removes "banana"
show(fruits) // ["apple", "mango", "grape"]
append()
adds an item at the endremove()
deletes the item (first match only)
Updating a List Item by Index
set fruits[0] to "orange"
- You can directly change any item by referring to its position
Nested Lists (2D Arrays) Example
declare grid[]
set grid to [["math", 90], ["science", 85]]
foreach row in grid
show(row[0] + ": " + row[1])
end foreach
- This simulates rows of data (like subject and score)
row[0]
is subject,row[1]
is score
Summary Table of List Features
Feature | Syntax Example | Description |
---|---|---|
Declare list | declare scores[] | Define an empty list |
Initialize list | set scores to [80, 85, 90] | Add values at once |
Mixed data list | ["Ali", 22, true] | Store different types in one array |
Get length | scores.length() / length(scores) | Find how many items in the list |
Access nested index | matrix[1][0] | Get value from sub-list |
Update value | set names[1] to "Amina" | Replace an item at specific index |
Loop (foreach) | foreach x in items ... end foreach | Read values directly |
Loop (for) | for i from 0 to arr.length()-1 ... | Use index-based loop |
Import functions | import remove, append from array | Import just what you need |
Use full module | array.append(arr, value) | Call via full module |
More Array Functions
You can do much more with lists using other available functions:
insert(arr, index, value)
– Add at specific indexcontains(arr, value)
– Check if value existsindex_of(arr, value)
– Get index of itemclear(arr)
– Remove all itemsreverse(arr)
– Flip the listsort(arr)
– Arrange in order
Visit the full documentation:
Array Module Reference
Conclusion
Lists in EasyBite give you the power to manage data efficiently. Whether you're dealing with simple names or complex grids, arrays are the foundation of data handling and looping. Practice with small lists first, then try nesting, importing functions, and building real apps with them.