Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

"for" loop in velocity template

I already posted a similar question a week ago on How to use 'for' loop in velocity template?.

So...basically I can't use 'for' loop in a velocity template.

Let's say I have a variable that holds integer 4. I want to display something four times using that variable. How do I do it in a velocity template?

question from:https://stackoverflow.com/questions/5735097/for-loop-in-velocity-template

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to do it like this:

#set($start = 0)
#set($end = 4)
#set($range = [$start..$end])
#foreach($i in $range)
   doSomething
#end

The code has not been tested, but it should work like this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...