如果条件在Eclipse rcptt中满足则从循环中退出

时间:2018-07-08 10:02:02

标签: eclipse eclipse-rcptt

如果要在Eclipse rcptt中满足条件,我想退出循环。

我正在使用以下代码:

proc "wait-until" [val iconName] {
    loop [val count 1] [val n 5] {
        if [$count | lt $n] {

            try{

                let [val text [get-button "Configure" | get-property "getToolTipText()" -raw]] {
                    if [$text | contains $iconName] {

                        recur [$count | plus 100] [$n]
                    }
                }
            } -catch {
                show-alert "inside catch"
            }

            recur [$count | plus 1] [$n]
        } -else {
        }
    }
}

但是如果尝试条件也满足,它将继续。

我在哪里做错了?

谢谢

2 个答案:

答案 0 :(得分:1)

RCTPT中的循环很奇怪,因为它们不只是迭代,而是像“递归”那样“深入”。

关键字“ recur”旨在表达这一点。

在您的情况下,如果try {}在第(n)次成功运行,它仍然必须“爬出”并在“ recur”指令(n-1)次之后执行代码部分。

如果可能的话,您应该重新组织代码以使“递归”作为循环中的最后一条指令。

答案 1 :(得分:0)

好吧,我想出了以下解决方案:

proc "wait-for-button" [val name] {
  loop [val count 0] {
  try {
      get-button $name
      } -catch {
              if [eq $count 300] { // 30 seconds
                  throw-error [concat "wait-for-button: Could not find button " $name]
              }
              wait 100
             recur [$count | plus 1]
     }//catch ends
  }//loop ends
}//proc -ends

它实际执行的操作将迭代300次。如果在try中找到一个按钮,它将停止执行。 如果没有,它将捕获到块并再次执行下一个递归。

相关问题