可以在这样的循环中重写:
for (; testParentPage != null; testParentPage = testParentPage.getParent()) {
testPages.push(testParentPage);
if(homePage != null && testParentPage.getPath().equals(homePage.getPath())){
isParent = true;
break;
}
}
我必须承认我不知道它是否有任何好处。
for(; testParentPage != null; testParentpage = testParentPage.getParent()) {
...
}
循环结构是(可变初始化;布尔测试;分配) - 通常变量是整数,测试是一个
,分配是增量,但不需要这种情况。
do .. while
for
或foreach
< or >循环将是首选工具。但是在这种情况下(使用一个loop循环浏览树结构)实际上会令人困惑。
在此外,始终评估了一个循环的条件
for
方法。
re:for-eashloop. 每个循环均以一个集合或数组迭代为(请参阅DOCS),因此您将无法(立即)将您的do-lile循环转换为for-each循环,因为您正在通过自定义进行迭代 - 定义的层次结构。
如果您有一个(或类型名称为此),它将起作用。所以
for
。或testParentPage
。