Problem

5/10

Iterating over the elements of an array

Theory Click to read/hide

When working with arrays, you usually have to work with all the elements of the array at once.
Iterating through the elements: we look through all the elements of the array and, if necessary, perform some operation on each of them.
For this, a loop with a variable is most often used, which changes from 0 to N-1, where N is the number of array elements.
Under N we will consider the current size of the array, that is
N := length(A)

...
for i := 0 to n - 1 do begin
     // here we work with a[i]
end;
...
In the specified loop, the variable i will take the values ​​0, 1, 2, ..., N-1.  Thus, at each step of the loop, we access a specific element of the array with the number i.
Thus, it is enough to describe what needs to be done with one element of the array a[i] and place these actions inside such a cycle.

Let's write a program that fills the array with the first N & nbsp; natural numbers, that is, at the end of the program, the elements of the array should become equal
a[0] = 1
a[1] = 2
a[2] = 3
...
a[N - 1] = N
It is easy to see the pattern: the value of an array element must be greater by 1 than the index of the element.
The loop will look like this
for i := 1 to n - 1 do
    a[i] := i + 1;

Complete the task.

Problem

1) Study the comments to the program
2) In block 1, make a loop that fills all the elements of the array with the values ​​of natural numbers from 1 to N