running a loop on a comma delimited list of items progress 4GL

Bill picture Bill · Apr 3, 2012 · Viewed 9.4k times · Source
def var cList as char no-undo.
assign cList = "one,two,three,four".
<Loop> cList
logic...
</Loop>

What's the best way to loop through a comma delimited list in a char variable so that in this example I would get one then two then three then four.

Answer

Abe Voelker picture Abe Voelker · Apr 3, 2012

Lol I still remember a bit of Progress I think.

DEF VAR i AS INT NO-UNDO.
&SCOPED-DEFINE LIST "one,two,three,four"

DO i=1 TO NUM-ENTRIES({&LIST}):
  MESSAGE SUBSTITUTE("LIST[&1] is &2", i, ENTRY(i, {&LIST})).
END.