简体   繁体   中英

While loop in Xtend

I have written a code in java and now I have to convert it to Xtend templates. However I have the following written with a while loop.

index = refin.size()-1
                    while (index > 0){
                          System.out.println(refin.get(index) + "::=" + refin.get(index-1))
                          index-=2
                        }

Now I see that Xtend templates do not support WHILE, and also I cannot write the following:

«FOR index : refin.size()-1 ; index >= 0 ; index -=2»

Any ideas on how I could use that while loop (or something similar) to do the same thing that I am doing there, in Xtend templates?

Many thanks!

For me it works fine

val String[] refin = #["1", "a", "2", "b", "3", "c"]
var index = refin.size - 1
while(index > 0) {
    println(refin.get(index) + "::=" + refin.get(index -1))
    index -= 2
}

// c::=3
// b::=2
// a::=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM