Do-While in Expect Script

I wrote the below code and try to execute it. But i face the "invalid command name "do" while executing do {"

code:

#!/usr/bin/expect
set val 0;
set input 5;

do {
    puts "\nval = $val"
    set input [expr $input-1];
    set val [expr $val+1];
} while {input}

Please let me know to fix this issue. Does do-while exist in Expect script?

1 Answer

The short answer is no.

The slightly longer answer is:

while true {
    puts "\nval = $val"
    incr val
    if {[incr input -1] == 0} break
}

The full discussion can be found on the Tcl wiki.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest