</>Learn to Write Code
LearnPseudocodeReal CodeLanguagesVideosCode TalkAbout
Learn → Programming Fundamentals → Lists & Collections

Programming Fundamentals

01Variables02Operators03Input & Output04Sequence05Conditions06Loops07Functions08Objects09Lists10Strings11Errors12Recursion13Inheritance
Lesson 9 of 13·Beginner

Lists & Collections

Store many values in one ordered group, reach any value by its position, and visit every item with a loop.

Related:listarraycollectionindexfor each

A list holds many values in one ordered group

A list stores several values together, in order, under one name.

Each value has a position in the list called an index. Indexes start counting at 0, so the first item is at index 0, not 1.

  • Store many related values in one list.
  • Reach a single value by its index position.
  • Add new values to the end of a list.
  • Visit every item with FOR EACH.
Think of a numbered row of mailboxes: mailbox 0 is the first one, not the "zeroth" one.
Try it: Given a list of colors ["Red", "Green", "Blue"], which index would get you "Green"? What would the list contain after you ADD "Yellow" to it?

Create a list, read an item, then loop over all of them

We look up the first fruit by index, add a new fruit to the end, then visit every fruit in order.

Pseudocode
CREATE fruits AS LIST WITH "Apple", "Banana", "Cherry"
SHOW ITEM 0 OF fruits

ADD "Date" TO fruits
SHOW LENGTH OF fruits

FOR EACH fruit IN fruits
    SHOW fruit
END FOR

The same idea in Python

Python lists index from 0, append with .append(), and support for...in directly over the list.

Python
fruits = ["Apple", "Banana", "Cherry"]
print(fruits[0])

fruits.append("Date")
print(len(fruits))

for fruit in fruits:
    print(fruit)

The same idea in JavaScript

JavaScript arrays use the same 0-based indexing, push() to add, and for...of to visit each item.

JavaScript
const fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[0]);

fruits.push("Date");
console.log(fruits.length);

for (const fruit of fruits) {
    console.log(fruit);
}

The same idea in C#

C# uses a List<string> for a growable collection, Add() to append, and foreach to visit each item.

C#
List<string> fruits = new List<string> { "Apple", "Banana", "Cherry" };
Console.WriteLine(fruits[0]);

fruits.Add("Date");
Console.WriteLine(fruits.Count);

foreach (string fruit in fruits)
{
    Console.WriteLine(fruit);
}

The same idea in Java

Java uses a List of String, get() to read by index, add() to append, and an enhanced for loop to visit each item.

Java
List<String> fruits = new ArrayList<>(List.of("Apple", "Banana", "Cherry"));
System.out.println(fruits.get(0));

fruits.add("Date");
System.out.println(fruits.size());

for (String fruit : fruits) {
    System.out.println(fruit);
}

The same idea in C++

C++ uses a std::vector for a growable list, push_back() to append, and a range-based for loop to visit each item.

C++
std::vector<std::string> fruits = {"Apple", "Banana", "Cherry"};
std::cout << fruits[0] << '\n';

fruits.push_back("Date");
std::cout << fruits.size() << '\n';

for (const std::string& fruit : fruits)
{
    std::cout << fruit << '\n';
}
Lesson 9 of 13 · Concept
← Previous Lesson: ObjectsNext Lesson: Strings →

Learn to Write Code

Learn the idea first, write it in pseudocode, then see how real programming languages express the same logic.

Learn

CurriculumPseudocode StandardLanguagesReal Code

Elsewhere

Code TalkAbout BrianSpread the WordCoders Rock — PracticecodeBetter on YouTubeSupporting files on GitHubAdvertising & Promotions
© 2026 Brian Kittrell, an exteran studios site. Educational content and examples are provided for learning purposes.