-
Notifications
You must be signed in to change notification settings - Fork 3
Lists & loops
Lists are a way to collect elements into a single place. In Pikt, an empty list can be created by calling the listOf(items...) 
Now this blue 
In the following example the list contains a 0 and a 1:
New elements can be added later by calling the addToList(list, items...) 
funcall 
The inverse is given by removeFromList(list, items...) 
The content of a list (or string) in a certain position can be accessed via the dot 
<list> dot <index> syntax, where index is a number, either directly used or stored in a variable.
The following example stores the first element of the list (index 0 

On the other hand, here we set the first element (previously 0 

See Accessing fields for further information about the
dotoperator.
The range(start, end) 
start up to (or down to) end, both inclusive.
In this example start is 0 and end is 10, so that [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is generated.
For-each 
foreach <list> <block>, where <block> is a block of code with an optional argument, that starts with lambda.open 
lambda.close 
The following piece of code prints each element of a list:
foreach <list> lambda.open <argument>
print <argument>
lambda.close
Given that the list is the blue 
The orange 
A break can be performed on loops by putting two return 
From the previous example:
This will print only the first element in the list before breaking the for-each loop. A break can be inserted inside nested blocks, such as if.







