Foreach loop with counter

后端 未结 2 964
遥遥无期
遥遥无期 2020-12-19 11:59

I would like to add a counter in this loop in order to know the row of each element of the list. Do you have a simple solution?

lists:foreach(fun(X) .... end,Y

2条回答
  •  心在旅途
    2020-12-19 12:48

    Use lists:foldl or write your own function:

    lists:foldl(fun(E,Cnt) -> ..., Cnt+1 end, 0, Y),
    

提交回复
热议问题