LastElement()

Syntax

LastElement(LinkedList())
Description
Change the current list element to the last list element.

Parameter:
LinkedList() - The name of your linked list variable, created with the NewList function. You must include the brackets after the list name.

Return value:
The value returned by this function can be used to show whether the last element exists or not (it will not exist if the list is empty). If the last item exists, this function will return a value which is not equal to zero. If the last element does not exist then it will return a value of zero.

Advanced users only:
The value that this function returns is a pointer to the last element data or zero if the last element does not exist.

Example:
  ; An example of simple usage
  NewList Numbers.w()

  AddElement(Numbers())
  Numbers() = 5
  AddElement(Numbers())
  Numbers() = 8

  LastElement(Numbers())
  MessageRequester("Information", "Last element value is "+Str(Numbers()), #PB_MessageRequester_OK)


  ; An example which uses the return value
  NewList Numbers.w()

  If LastElement(Numbers()) <> 0
    MessageRequester("Information", "Last element value is "+Str(Numbers()), #PB_MessageRequester_OK)
  Else
    MessageRequester("Information", "List is empty", #PB_MessageRequester_OK)
  EndIf

  AddElement(Numbers())
  Numbers() = 5
  AddElement(Numbers())
  Numbers() = 8

  If LastElement(Numbers()) <> 0
    MessageRequester("Information", "Last element value is "+Str(Numbers()), #PB_MessageRequester_OK)
  Else
    MessageRequester("Information", "List is empty", #PB_MessageRequester_OK)
  EndIf


  ; An example which is only for advanced users
  NewList Numbers.w()

  AddElement(Numbers())
  Numbers() = 5
  AddElement(Numbers())
  Numbers() = 8

  *Element.Word = LastElement(Numbers())
  If *Element
    MessageRequester("Information", "Last element value is "+Str(*Element\w), #PB_MessageRequester_OK)
  Else
    MessageRequester("Information", "List is empty", #PB_MessageRequester_OK)
  EndIf

Supported OS

All

<- InsertElement() - LinkedList Index - ListIndex() ->