Wolfram Computation Meets Knowledge

The Wolfram Language:
Fast Introduction for Programmers

Show additional notes for:
All sections 
Get Started

Iterators Video Version

Notes for Java programmers:

Not to be confused with Java's Iterator interface, the Wolfram Language's iterator notation reduces the code required for repetitive operations. Generally, these iterators are used for tasks that would require loops in Java.

Make a table of the first 10 squares:


Many functions in the Wolfram Language use the standard "iterator specification": min, max, step:


Notes for Java programmers:

In Java, iterative operations like this would require a for or while loop.

An alternative iterator specification just gives an explicit list of values:


Notes for Java programmers:

Using Table this way is analogous to iterating over a Java array or collection with a foreach construct.

Notes for Python programmers:

Using Table in this way is analogous to using the [... for ... in ...] list comprehension construct in Python, though it has somewhat richer semantics.

This makes a nested table:


Which of these makes a table of the first 20 numbers?

What is the first element of the list produced by Table[f[x], {x, {3, 4, 6}}]?

Which one of these evaluates to the list of squares {1, 4, 9, 16}?

© 2024 Wolfram. All rights reserved.