0
Xaxis:array[1..10] of integer;
begin 
Xaxis[1] :=10;
Xaxis[2] :=20;
Xaxis[3] :=30;
Xaxis[4] :=40;
Xaxis[5] :=50;
Xaxis[6] :=60;
Xaxis[7] :=70;
Xaxis[8] :=80;
Xaxis[9] :=90;
Xaxis[10] :=100;

is there a simpler and quicker way of declaring values for an array that this in pascal ?

0

3 Answers 3

1

Use a for loop:

for num := 1 to High(Xaxis) do 
begin
  Xaxis[num] := num * 10
end;

But first be sure to declare 'num' as an Integer.

Sign up to request clarification or add additional context in comments.

Comments

0

Use a loop. I forget pascal's syntax but something like Xaxis[index] := index * 10; inside a loop would work.

Comments

0

You could also pre-initialise the array by writing

const
 Xaxis: array[1..10] of integer = (10, 20, 30, 40, 50, 60, 70, 80, 90, 100);

This approach is better when there's no simple arithmetical function to initialise the array. Had you written xaxis[1]:= 5, xaxis[2]:= 14, xaxis[3]:= 29, etc, then loops would not have been suitable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.