Cross Training Home Development Chat Log Concept #1 — Iterate & Display
TNT  ›  Cross Training  ›  Iterate & Display
Concept #1

Iterate & Display

Loop over a collection. Do something with each item.
The building block of almost everything — seen here in three languages.

What the Movie Credits App is Really Doing

Behind the starfield, the cinematic fonts, and the Superman-style zoom effect, the Movie Credits Simulator is doing something simple: it has a list of names, and for each name, it does something with it.

That’s iteration. Every language you’ll ever use has a way to express this idea. The syntax changes. The vocabulary changes. The concept does not.

The three code examples below show the same logic — a list, a loop, an action on each item — in p5.js, Java, and Python 3. The animation, the colors, and the music are all stripped away. What’s left is the idea.

The concept, before any language

// Given a list of items:
CREATE a list containing several names

// Iterate it — visit each one:
FOR EACH name IN the list:
DO something with name
// here: display it on screen (or print to console)

Every language below is a direct translation of these four lines. The concept is identical — only the vocabulary differs.

The Same Idea in Three Languages

Same concept. Same data. Same action. Different syntax. Study what’s the same — and what each language makes you say differently.

p5.js JavaScript / p5.js 1.7
// The data: a list of names
let names = [
  "Alice Johnson",
  "Bob Martinez",
  "Carmen Wu",
  "David Okafor",
  "Eva Petersen"
];

function setup() {
  createCanvas(400, 300);
  textAlign(CENTER, CENTER);
  noLoop(); // draw once is enough
}

function draw() {
  background(0);
  colorMode(HSB, 360, 100, 100);
  textSize(24);

  // Iterate — display each name
  for (let i = 0; i < names.length; i++) {
    let hue = (i / names.length) * 360;
    fill(hue, 80, 100);
    let y = 40 + i * 50;
    text(names[i], width / 2, y);
  }
}
Java Java 17+
import java.util.ArrayList;

public class IterateAndDisplay {

    public static void main(String[] args) {

        // The data: a list of names
        ArrayList<String> names = new ArrayList<>();
        names.add("Alice Johnson");
        names.add("Bob Martinez");
        names.add("Carmen Wu");
        names.add("David Okafor");
        names.add("Eva Petersen");

        // Iterate — print each name
        for (String name : names) {
            System.out.println(name);
        }
    }
}
Python 3 Python 3.x
# The data: a list of names
names = [
    "Alice Johnson",
    "Bob Martinez",
    "Carmen Wu",
    "David Okafor",
    "Eva Petersen"
]

# Iterate — print each name
for name in names:
    print(name)

Why Does Each Version Look Different?

The guiding question for every Cross Training page: “What does each version reveal about the language’s personality?” This is the section that sticks. This is what you say in an interview when someone asks you to walk them through how you think about languages.

p5.js / JavaScript

Visual immediacy. The same iteration that prints names to a console puts them on a canvas. JavaScript’s for loop is syntactically identical to Java’s — but the environment (a browser, a canvas, a 60 fps draw loop) changes everything about what iteration can do.

JavaScript evolved in a browser and carries that origin everywhere. Flexibility first. There are three or four ways to write this loop because the language never throws anything away.

Java

Explicitness and safety. You declare the type of every variable so the compiler can catch your mistakes before they reach production. ArrayList<String> tells both the programmer and the compiler exactly what kind of data lives here.

The enhanced for-each loop (for (String name : names)) reads almost like English once you know what <String> means. Java is verbose by design — the verbosity is the documentation.

Python 3

Readability matters more than brevity. Indentation IS the syntax — there are no curly brackets because the language trusts you to be consistent. for name in names: is close enough to plain English that you almost don’t need to explain it.

Python is designed to be read by humans first and executed by computers second. It strips out every piece of ceremony that doesn’t add meaning. That’s why the list of names and the loop are each half the size of their Java equivalents.

Tier 3 — The Workshop Version

The Teacher’s Programs

These programs do the same thing as the snippets above — but they add time.sleep() for a real credits feel, use the full movie cast from The Last Signal, and replace the explanatory comments in the Tier 2 panels with a running Python–Java comparison baked directly into the code. Copy them, paste into VS Code or a terminal, and run. They need no browser.

Python 3 movieCreditsDemo.py
# movieCreditsDemo.py — Workshop Version
# ─────────────────────────────────────────
# Python's philosophy: READABILITY first.
# Indentation IS the syntax — no curly braces.
# No type declarations: Python figures them out as it runs.
# Less ceremony, more clarity — a deliberate design choice.
# ─────────────────────────────────────────

import time   # Java has Thread built in; Python requires this import.

# Java:    String[] credits = {"THE LAST SIGNAL", ...};
#          ^^^^^^^^ type required — "an array of text values"
# Python:  credits = [...]
#          No type. Python sees [ ] and knows it’s a list.

credits = [
    "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
    "   T H E   L A S T   S I G N A L",
    "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
    "",
    "Directed by",
    "    Ava Chen",
    "",
    "Produced by",
    "    Marcus Webb",
    "    Priya Nair",
    "",
    "Original Score",
    "    Theo Lindqvist",
    # ... full cast in source file
]

print()

# Java:    for (int i = 0; i < credits.length; i++) { ... }
#          Three parts: start / stop / step — all explicit.
# Python:  for credit in credits:
#          One line. No counter. No length check. No brackets.

for credit in credits:
    print("  " + credit)

    # Java:    Thread.sleep(1000);  + required try-catch
    # Python:  time.sleep(1)        — one line, no exception handling
    #
    # Java forces you to acknowledge that sleep() can be interrupted.
    # Python trusts you to decide when it matters.

    time.sleep(1)

print()
print("  [ end of credits ]")
Java MovieCreditsDemoDriver.java
// MovieCreditsDemoDriver.java — Workshop Version
// ─────────────────────────────────────────
// Java's philosophy: EXPLICITNESS and SAFETY.
// The compiler reads your code before it runs. Declaring types
// lets it catch mistakes at compile time — before they reach
// the user. Python trusts you at runtime. Java checks first.
// ─────────────────────────────────────────

public class MovieCreditsDemoDriver {

    public static void main(String[] args) {

        // Python:  credits = ["THE LAST SIGNAL", ...]
        // Java:    String[] credits = {"THE LAST SIGNAL", ...};
        //          String[] ← type required — Java won’t let you skip it.

        String[] credits = {
            "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
            "   T H E   L A S T   S I G N A L",
            "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
            "",
            "Directed by",
            "    Ava Chen",
            "",
            "Produced by",
            "    Marcus Webb",
            "    Priya Nair",
            "",
            "Original Score",
            "    Theo Lindqvist",
            // ... full cast in source file
        };

        System.out.println();

        // Python:  for credit in credits:
        // Java:    for (int i = 0; i < credits.length; i++)
        //          Three parts: start (int i=0) / stop / step (i++)
        //          credits.length ≈ Python’s len(credits)

        for (int i = 0; i < credits.length; i++) {
            System.out.println("  " + credits[i]);

            // Python:  time.sleep(1)       — seconds, one line
            // Java:    Thread.sleep(1000); — milliseconds + try-catch
            //
            // Java forces you to acknowledge InterruptedException.
            // You must prove you thought about the edge case.

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        System.out.println();
        System.out.println("  [ end of credits ]");
    }
}