Array Initialization: Difference between revisions

(→‎Mathematica: Covered in Creating an Array)
(→‎Modula-3: Covered)
Line 182:
array ((0,0),(5,5)) [((0,0),0),((0,1),0),((0,2),0),((0,3),0),((0,4),0),((0,5),0),((1,0),0),((1,1),0),((1,2),0),((1,3),0),((1,4),0),((1,5),0),((2,0),0),((2,1),0),((2,2),0),((2,3),0),((2,4),0),((2,5),0),((3,0),0),((3,1),0),((3,2),0),((3,3),0),((3,4),0),((3,5),0),((4,0),0),((4,1),0),((4,2),0),((4,3),0),((4,4),0),((4,5),0),((5,0),0),((5,1),0),((5,2),0),((5,3),0),((5,4),0),((5,5),0)]
</lang>
 
==[[Modula-3]]==
The usual module and import code is omitted.
<lang modula3>VAR arr := ARRAY [1..10] OF INTEGER {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
VAR arr1 := ARRAY [1..10] OF INTEGER {1, ..} (* Initialize all elements to 1. *)</lang>
Array initialization doesn't have to be used in the array declaration.
<lang modula3>TYPE Vector: ARRAY OF INTEGER;
VAR arr: Vector;
arr := Vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};</lang>
 
==[[Python]]==
Anonymous user