In this code I want to increment index
to put it to each yield
ing result.
var index=0
for(str <- splitToStrings(text) ) yield
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.