In programming, lists are a basic data structure that stores multiple pieces of information in an ordered, linear sequence.
myList = ["apple", "banana", "grapes"]
In programming, data structures are an organized way to access and manage data.
In programming, the position of a value in a list is known as its index. An item in a list can be accessed by its index.
myList = ["apple", "banana", "grapes"]myList[1] //returns ‘banana’, if a list is zero-indexed
In programming, when item is added to the end of a list, this is known as appending.
myList = ["apple", "banana", "grapes"]myList.append("pear") // adding an item to the end of a list in javascript// returns ["apple", "banana", "grapes", "pear"]
In programming, a for each loop executes a set of instructions for each item in a given collection.
A for each loop to add a list of destinations to a tourism application may look like this:
FOR EACH destination in the list:
Add destination to app
In programming, a for loop executes a set of instructions for a specified number of times.
A for loop to add landmarks to a map may look like this:
UNTIL 20 landmarks have been added to the map:
Add landmark to map
In programming, a while loop executes a block of code as long as a given condition evaluates to true.
A while loop to make sandwhichs as long as there is bread left may look like this:
WHILE there is bread left:
Make a sandwich