# `LoopList`

digraph inheritance17a76094b8 { bgcolor=transparent; rankdir=UD; ratio=compress; size="8.0, 12.0"; "LoopList" [URL="#taurus.core.util.containers.LoopList",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="this class provides an effectively cyclic list. It can be used, e.g.,"]; }

class LoopList(itemlist=[])

  this class provides an effectively cyclic list. It can be used, e.g., for storing colors or pen properties to be changed automatically in a plot

  A LoopList stores an internal index to remember the last accessed item in the list. It provides previous(), current() and next() methods that return the previous, current and next items in the list.

  The method allItems() returns a copy of all items contained in the list.

  The index can be accessed by setCurrentIndex() and getCurrentIndex() (setCurrentIndex(i) additionally returns new current item).

  Items can be accessed *without modifying the current index* by using llist[i] and llist[i]=x syntax len(llist) returns the period of the list.

  Note

  only basic methods of lists are implemented for llists. In particular, the following are not implemented:

  > - slicing

  > - resizing (append, insert, del,…)

  > - binary operators (+,*,…)

  ..note:

      it can be used for loops, but the loop will be infinite unless other
      condition is used for exiting it:

          - for item in llist: print(item)  # This is a infinite loop!!
          - for i in range(len(llist)):print(llist[i])  # not infinite
            since len(llist) returns the period of the list

  Import from `taurus.core.util.containers` as:

      from taurus.core.util.containers import LoopList

  allItems()

    returns the items list (one period)

  current()

    returns current item

  getCurrentIndex()

    returns the current index

  next()

    advances one item in the list and returns it

  previous()

    goes one item back in the list and returns it

  setCurrentIndex(index)

    sets current index (and returns the corresponding item)

  setItemList(itemlist)

    sets the item list