推荐的方法来编写多个IFS的条件

发布于 2025-02-12 14:23:41 字数 694 浏览 1 评论 0原文

如果4个计数器变量中的任何2个非零,我正在尝试提醒用户。 如果有这样的条件,那么在没有很长时间的情况下编写编码的最佳方法是什么?

#   Description: report violation if any 2 type of device counts is non-zero (mix of Vt cells)
if { $count_hvt >0 && ($count_lvt >0 || $count_ulvt>0 ||$count_svt >0 ) } {
    return 1
} elseif { $count_lvt >0 && ($count_hvt >0 || $count_ulvt>0 ||$count_svt >0 ) } {
    return 1
} elseif { $count_svt >0 && ($count_hvt >0 || $count_lvt>0 ||$count_ulvt >0 ) } {
    return 1
} elseif { $count_ulvt >0 && ($count_hvt >0 || $count_lvt>0 ||$count_svt >0 ) } {
    return 1
} else {
    #puts "-0- return 0"
    return 0
}

I am trying to do alert the user if any 2 of the 4 counter variables is non-zero.
What is the best way to code this without a long if else condition like this?

#   Description: report violation if any 2 type of device counts is non-zero (mix of Vt cells)
if { $count_hvt >0 && ($count_lvt >0 || $count_ulvt>0 ||$count_svt >0 ) } {
    return 1
} elseif { $count_lvt >0 && ($count_hvt >0 || $count_ulvt>0 ||$count_svt >0 ) } {
    return 1
} elseif { $count_svt >0 && ($count_hvt >0 || $count_lvt>0 ||$count_ulvt >0 ) } {
    return 1
} elseif { $count_ulvt >0 && ($count_hvt >0 || $count_lvt>0 ||$count_svt >0 ) } {
    return 1
} else {
    #puts "-0- return 0"
    return 0
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一枫情书 2025-02-19 14:23:41

也许基本上是这样

set counters [list $count_hvt $count_lvt $count_svt $count_ulvt]
if {[llength [lsearch -all -exact -integer -not $counters 0]] >= 2} {
    return 1
}

,从列表中滤除等于零的元素,并计算剩下多少元素。

Maybe something like

set counters [list $count_hvt $count_lvt $count_svt $count_ulvt]
if {[llength [lsearch -all -exact -integer -not $counters 0]] >= 2} {
    return 1
}

Basically, filter out the elements equal to zero from a list, and count how many remain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文