Forum Discussion

Dicken's avatar
Dicken
Post Prodigy
1 year ago
Solved

List Positions

  Can some one explain what is happenign here so, straightforward  position;   [ alist = {1,3,2,"a",2,2,2,2,"a",2,2,2,2,"a",2,2} , result = List.PositionOf( alist, "a",Occurrence.All) ]  but her...
  • p45cal's avatar
    p45cal
    1 year ago

    There's guaranteed to be an error in the last member of the list (you're referring to x+1 which doesn't exist).

    Using an otherwise = true will mask that error which is fine, although as a coder you'll realise this masks any other error that may appear in the list and you wouldn't be alerted to it. My approach would be to remove the known error at the end of the list with a List.RemoveLastN(tflist,1) (or do it in the same line) so that you're only removing the expected error, then do your ListPositionOf with Occurence.All.