Difference between revisions of "Arrays.Pop"

From Xojo Documentation

(Sample Code)
(See Also)
Line 65: Line 65:
== See Also ==
== See Also ==
[[Var]] statement; [[Arrays]] concept for a full list of functions; [[ParamArray]] keyword, [[Arrays.AddRow|AddRow]] method
[[Var]] statement; [[Arrays]] concept for a full list of functions; [[ParamArray]] keyword, [[Arrays.Add|Add]] method

Latest revision as of 16:04, 24 January 2022



Supported for all project types and targets.

Removes the last element from an array and returns its value.


result = array.Pop

Part Type Description
result Same as array The element of array that was removed.
array Any valid data type for an array The array from which the last value will be popped.


The Add and Pop methods can be used together to treat an array as a stack.The Add method pushes a new element onto the array/stack and the Pop method removes the last element from the array/stack and returns its value.

If array has no values then an OutOfBoundsException is raised.

Sample Code

This example pushes "One", "Two", "Three" onto an array used as a stack and then Pops the values off in reverse order:

Var stack() As String


MessageBox(stack.Pop) // Three
MessageBox(stack.Pop) // Two
MessageBox(stack.Pop) // One

This is a directory-crawling routine that performs a depth-first traversal without using recursion:

Var itemsToInspect(0) As FolderItem
Var item As FolderItem
Var folder As FolderItem
folder = FolderItem.ShowSelectFolderDialog
If folder.Exists Then
itemsToInspect(0) = folder
While itemsToInspect.LastRowIndex >= 0
item = itemsToInspect.Pop
If item.IsFolder Then
For Each file As FolderItem In item.Children
End If
End If

See Also

Var statement; Arrays concept for a full list of functions; ParamArray keyword, Add method