Table of Contents
Reversing Arrays
RhinoScript
Version: Rhino 4.0
Summary: Demonstrates how to reverse an array using RhinoScript.
Question
How can I quicky reverse the order of the elements in an array?
Answer
Consider the following subroutine:
Sub ReverseArray(ByRef arr) Dim i, j, last, half, temp last = UBound(arr) half = Int(last/2) For i = 0 To half temp = arr(i) arr(i) = arr(last-i) arr(last-i) = temp Next End Sub
This can be used as follows:
Sub Main() Dim arr, i arr = Array(1,2,3) For i = 0 To UBound(arr) Rhino.Print arr(i) Next Call ReverseArray(arr) For i = 0 To UBound(arr) Rhino.Print arr(i) Next End Sub