TCL:循环如何从最内层循环到外部? [英] TCL: loops How to get out of inner most loop to outside?

查看:77
本文介绍了TCL:循环如何从最内层循环到外部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,当我将check_access设置为0时,如何保存该值并点击 如果条件低于($ check_root&& $ check_access).中断只会终止内部循环.但是其他循环将按照我的方式继续.

In the below code once I hit check_access as 0 how do I preserve the value and hit the if condition below ($check_root && $check_access) . Break will only terminate the inner loop. But the other loops will continue as per me.

   } else {
           set check_access 0
           break
         }
      }
   }
   if {$check_root && $check_access} {
    set result 1
  } else {
    set result 0
  }

推荐答案

breakcontinue操作仅循环一级.如果您还需要更多,请 考虑重构 ,这样您就可以return了.或者,在Tcl 8.6中尝试自定义异常:

The break and continue operations only go out one level of looping. If you need more than that, consider refactoring so that you can just return. Alternatively, try a custom exception in Tcl 8.6:

try {
    foreach a $longList1 {
        foreach b $longList2 {
            if {[someCondition $a $b]} {
                # Custom non-error exception
                return -level 0 -code 123
            }
        }
    }
} on 123 {} {
    # Do nothing; we're out of the loop
}

这篇关于TCL:循环如何从最内层循环到外部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆