Answer the question
In order to leave comments, you need to log in
How to swap adjacent elements of a one-dimensional array?
There is a procedure that swaps the values of variables: How can I use it to swap adjacent elements of a one-dimensional array filled with ten random two-digit numbers?
Answer the question
In order to leave comments, you need to log in
You iterate over the elements of the array through a loop with a step:
For i = 0 to Ubound(array) Step 2
That is, in pairs. And in the loop you change the values of the elements:
array(i)
array(i+1)
using a temporary variable, as in your example.
It is advisable to check before that that the array has an even number of elements.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question