1
0
-1

Hello,

Removing occurrences inside a forentity for the same entity is described as not recommended in the documentation.

E.g.:

forentity "ENTITY1"

    remocc

endfor

The following code wouldn't achieve much on its own, but is the general act of changing vList inside the forlist also unsupported or not recommended? I have seen similar code in use and while I think it looks risky, I'd like to know if it is actually supported or not.

while (vList != "")

forlist
vItem, vIndex in vList if (<condition>)
delitem vList, vIndex
break
endif
endfor

; More code

endwhile


Equally, items could be added to vList within the loop, instead of being deleted, is this also unsupported?

If unsupported, could this be added to the documentation so that this would be clear to developers?

Thanks.

    CommentAdd your comment...

    4 answers

    1.  
      2
      1
      0

      Hello Rupert,

      In the doc for forlist it says:

      "The Index can be altered by the code in the loop, which enables you to conditionally make changes in the loop as it executes."

      So this will actually work:

          forlist vItem, vIndex in vList 
              if (<condition>)
      delitem vList, vIndex
      vIndex =- 1
      endif
      endfor

      The same is true for adding items to a list. You just have to make sure that the value of Index is updated accordingly.

      I hope this helps.

      Kind regards,
      Daniel Iseli

        CommentAdd your comment...
      1.  
        1
        0
        -1

        If you first do a count of items in your list or entity, you could then use a "for" loop setting the StartValue to list / entity count, EndValue to 1 and StepValue to -1 to traverse the list/entity from back/last to front/first.

          CommentAdd your comment...
        1.  
          1
          0
          -1

          Hi all,

          When you need to clean an entity discard-ing/remocc-ing occurrences or when you need to clean a list with delitem the best choice would be to navigate your entity or your list backward from the end to the start.

          Unfortunately forentity and forlist do not enable (yet!) going backward while looping.

          I've opened a wish on the subject that can be found at this page while being logged in; if it is also a wish for you let support to know it to raise priority on its implementation.

          Regards,
          Gianni

            CommentAdd your comment...
          1.  
            1
            0
            -1

            Ah, ok, you can manually change the list but you must then manually update the index. 

            I think the documentation would benefit from being clearer on this, perhaps with an example, as it's not obvious that "conditionally make changes in the loop" means manually change the list.

            Thanks Daniel.

            1. Daniel Iseli

              Thanks. On each page of the Uniface Library there is a handy link for providing feedback:

              "Send feedback about this topic to Uniface."

              I hope this helps.

            CommentAdd your comment...