Scala for-loop. Getting index in consice way

后端 未结 4 1247
广开言路
广开言路 2020-12-31 16:17

In this code I want to increment index to put it to each yielding result.

var index=0

for(str <- splitToStrings(text) ) yield           


        
4条回答
  •  北海茫月
    2020-12-31 17:00

    Because initially index is set to 0, thus your condition index != 0 is never executes to true and index is never got incremented. Maybe you don't need this condition? Maybe you can count results afterwards? Now I see that index is used within loop. Then you have to either use @BenJames answer or go recursive.

提交回复
热议问题