Skip to content
C272 edited this page Aug 21, 2019 · 3 revisions

A list in Algo is defined as an array of values, accessible by an index. To create an array in Algo, you can define a variable like so:

let myList = [1, 2, 3, 4];

Lists are accessed with a 0-based index, meaning to access the first item in the list you use the index '0', and the second item with a '1', and so on. Here's an example of how you can access individual items in lists.

print myList[0]; //prints "1"

You can also create 2D, 3D or deeper arrays, by embedding lists within lists. These are accessed by using a comma to separate the indexes, from shallowest to deepest. Here's an example of that:

let multiDimList = [[1, 2], [3, 4]];
print multiDimList[0, 1]; //prints "2"

Adding and removing values from lists is remarkably simple. You use the "add" and "remove" functions to push something to the end of the list and remove specific items from the list.

//Add and remove normally.
add "hello" to myList;
remove "hello" from myList;

//Remove and add with index.
add "hello" to myList at 0; //insert at index 0
remove 0 in myList; //remove at index 0
remove "hello" from myList; //remove the item "hello"

Standard Library Documentation:

Clone this wiki locally