And just for fun here's a little word-counting algorithm that doesn't require any recursion:
<values>
/ mysentence = "The quick brown fox jumps over the lazy dog."
</values>
<expressions>
/ nwords = length(values.mysentence)-length(replaceall(values.mysentence," ",""))+1
</expressions>
<text mytext>
/ items = ("The sentence ~"<%values.mysentence%>~" contains <%expressions.nwords%> words.")
</text>
Regards,
~Dave