简体   繁体   English

Xtend 中的 while 循环

[英]While loop in Xtend

I have written a code in java and now I have to convert it to Xtend templates.我已经在 java 中编写了代码,现在我必须将其转换为 Xtend 模板。 However I have the following written with a while loop.但是我用 while 循环编写了以下内容。

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:现在我看到 Xtend 模板不支持 WHILE,而且我也不能写以下内容:

«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?关于如何使用 while 循环(或类似的东西)在 Xtend 模板中做我在那里做的同样的事情的任何想法?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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