Tcl : While command

Basic syntax for while command in tcl language is

while test body

Tcl also have break and continue command as found on other language to control looping. Break within body will exit the loop. Continue will stop executing body and reevaluate the test.

Consider below sample :

We use condition x < 100 on test parameter of while command. x initially set to 1 then incremented on body parameter of while command. On body we have condition to do break which is x > 5 after increment. The result is printing 1 to 5 on screen.

Same result with example before but we want to skip printing 3, here we go :

Here we have condition on body to execute continue command when x=3 and effectively not executing puts command which exist after continue command.

Bye for now. Watch some HIS DARK MATERIAL movie show.


Leave a Reply

Your email address will not be published. Required fields are marked *