Expect 脚本 - For 循环 - 如何使用超过 1 个变量

Expect Script - For Loop - How to use more than 1 variable

如何在 expect 脚本“for 循环”中使用 1 个以上的变量?请帮忙。 提前致谢。

有一个变量:

for {set i 1} {$i < 256} {incr i 1} {

}

2 或 3 个变量怎么可能,比如 init ,条件,增量 ijk ? 逗号、分号不起作用。

谢谢, 奎师那

请记住,expect 是 Tcl 的扩展。 Documentation of Tcl 可用。

for的语法是:

for start test next body

“开始”和“下一步”都被评估为脚本。 “测试”是一个 expr 会话

你可以做到:

for {set i 1; set j 10; set k "x"} {$i < 5 && $j > 0} {incr i; incr j -2; append k x} {
    puts "$i\t$j\t$k"
}

产出

1   10  x
2   8   xx
3   6   xxx
4   4   xxxx

这等同于以下内容,因此请使用最易读的内容。

set i 1
set j 10
set k "x"

while {$i < 5 && $j > 0} {
    puts "$i\t$j\t$k"

    incr i
    incr j -2
    append k x
}

事实上,您也可以在 for 命令中自由使用换行符

for {
    set i 1
    set j 10
    set k "x"
} {
    $i < 5 && $j > 0 
} {
    incr i
    incr j -2
    append k x
} {
    puts "$i\t$j\t$k"
}