Skip to main content

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/NAccess TypeExampleDescription
1Dot Notationitems.length()Access built-in functions directly from the list variable
2Module-Basedarray.remove(items, "apple")Use functions through the full array module
3Shorthand 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 named mixed
  • 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 the length() 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 end
  • remove() 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

FeatureSyntax ExampleDescription
Declare listdeclare scores[]Define an empty list
Initialize listset scores to [80, 85, 90]Add values at once
Mixed data list["Ali", 22, true]Store different types in one array
Get lengthscores.length() / length(scores)Find how many items in the list
Access nested indexmatrix[1][0]Get value from sub-list
Update valueset names[1] to "Amina"Replace an item at specific index
Loop (foreach)foreach x in items ... end foreachRead values directly
Loop (for)for i from 0 to arr.length()-1 ...Use index-based loop
Import functionsimport remove, append from arrayImport just what you need
Use full modulearray.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 index
  • contains(arr, value) – Check if value exists
  • index_of(arr, value) – Get index of item
  • clear(arr) – Remove all items
  • reverse(arr) – Flip the list
  • sort(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.