Codecademy Logo

Basics of Programming III

List Definition

In programming, lists are a basic data structure that stores multiple pieces of information in an ordered, linear sequence.

myList = ["apple", "banana", "grapes"]

Data Structure Definition

In programming, data structures are an organized way to access and manage data.

List Index Definition

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

List Append Definition

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"]

For Each Loop Definition

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

For Loop Definition

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

While Loop Definition

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

Learn More on Codecademy