Const Array



Const Array
Smart pascal source code
{ main.pas } Begin // -----> CASE I <------- const a : array [1..4] of Integer = [11, 22, 33, 44]; var i : Integer; WriteLn(a[1]); WriteLn(a[2]); WriteLn(a[3]); WriteLn(a[4]); for i:=Low(a) to High(a) do WriteLn(a[i]); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> 11 22 33 44 11 22 33 44 } // -----> CASE II <------- const ac : array [1..4] of Integer = [11, 22, 33, 44]; var aa := ac; WriteLn(aa[1]); WriteLn(aa[2]); WriteLn(aa[3]); WriteLn(aa[4]); for i:=Low(aa) to High(aa) do WriteLn(aa[i]); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> 11 22 33 44 11 22 33 44 } // -----> CASE III <------- type TEnum = (en1, en2, en3); const ace : array [TEnum] of String = ['one', 'two', 'three']; const ac2 = ace; var j : TEnum; for j in TEnum do WriteLn(ace[j]); for j in TEnum do WriteLn(ac2[j]); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> one two three one two three } // -----> CASE VI <------- type TEnum2 = (en1, en2, en3); type TEnumArray = array [TEnum2] of string; const acb : TEnumArray = ('one', 'two', 'three'); const ac21 : TEnumArray = acb; var k : TEnum2; for k in TEnum2 do WriteLn(acb[k]); for k in TEnum2 do WriteLn(ac21[k]); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> one two three one two three } // -----> CASE V <------- const X: array [0..1, 0..2] of Integer = [[1, 2, 3], [4, 5, 6]]; WriteLn(X[0,0]); for var w := Low(X) to High(X) do for var z := Low(X[w]) to High(X[w]) do WriteLn(IntToStr(w)+', '+IntToStr(z)+' : '+IntToStr(X[w, z])); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> 1 0, 0 : 1 0, 1 : 2 0, 2 : 3 1, 0 : 4 1, 1 : 5 1, 2 : 6 } // -----> CASE VI <------- type TDayTable = array[1..12] of Integer; const { True=Leapyear } cMonthDays: array [boolean] of TDayTable = ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)); for var m := 1 to 12 do WriteLn(cMonthDays[False, m].ToString+' vs '+cMonthDays[True][m].ToString); { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> 31 vs 31 28 vs 29 31 vs 31 30 vs 30 31 vs 31 30 vs 30 31 vs 31 31 vs 31 30 vs 30 31 vs 31 30 vs 30 31 vs 31 }