Wolfram: Loop
Procedural Style Loop
Do-loop
The Do function syntax is same as
Table.
but it just return Null.
Do allows the use of
Return,
Break,
Continue,
Throw
to exit and return a alternative value.
Do[Print[2], 4] (* print 2, 4 times *) (* return Null *)
Do[Print[n], {n, 4}] (* print 1 2 3 4 *)
(* nested loop, iterate over n, and m. *) Do[Print[n,m], {n, 3}, {m, 2}] (* 11 12 21 22 31 32 *)
(* use a literal list of values. *) Do[Print[i], {i, {1, 3, 20}}] (* 1 3 20 *)
Foreach
For-loop
For loop is basically never used in WolframLang, except in beginner code.
Use Do, Scan, Table, Map. See Wolfram: Iteration
For[i = 1, i < 9, i++, Print[i]]
While-loop
While loop is basically never used in WolframLang, except in beginner code.
n = 1; While[n < 4, Print[n]; n++]
Wolfram. List Operations, and Loop, Iteration, Recursion
- Wolfram: List Operations
- Wolfram: List. Create (Table)
- Wolfram: Create Flat List (Range)
- Wolfram: List. Get Parts
- Wolfram: List. Add Element
- Wolfram: List. Delete Element
- Wolfram: List. Change Element
- Wolfram: List. Check Exist
- Wolfram: List. Join, Union, Intersection, Difference
- Wolfram: List. Min, Max
- Wolfram: List. Filter
- Wolfram: List. Sort Reverse Ordering
- Wolfram: Flatten
- Wolfram: Riffle (Add at Every Nth)
- Wolfram: RotateLeft
- Wolfram: Padding
- Wolfram: List. Partition, Reshape, Split, Gather
- Wolfram: Transpose
- Wolfram: List. Same Items Counts, Tally, Group
- Wolfram: List. Combinatorics
- Wolfram: Iteration
- Wolfram: Map Function to List
- Wolfram: Scan (foreach)
- Wolfram: Recursion
- Wolfram: Fold (reduce)
- Wolfram: Loop