Array bounds



Array bounds test [positive range]
Smart pascal source code
var az : array[0..4] of Integer; a : array[5..9] of Integer; procedure ONE(); var i: Integer; begin Writeln('zero-based array'); for i := Low(az) to High(az) do begin az[i] := i; Writeln(IntToStr(i)); end; try i := -1; az[i] := 0; except on e: Exception do Writeln(e.Message); end; try i := 5; az[i] := 0; except on e: Exception do Writeln(e.Message); end; end; procedure TWO() var i: Integer; begin Writeln('five-based array'); for i := Low(a) to High(a) do begin a[i] := i; Writeln(IntToStr(i)); end; try i := 0; a[i] := 0; except on e: Exception do Writeln(e.Message); end; try i := 10; az[i] := 0; except on e: Exception do Writeln(e.Message); end; end; begin One; // zero-based array // 0,1,2,3,4 WriteLn('---------------'); Two; // five-based array // 5,6,7,8,9