Name

if

if expr1 [then] body1 [elseif expr2 [then] body2...] [else] [bodyN]

Execute a conditional expression. If boolean expression expr1 is true, evaluate body1. Otherwise, test optional additional expressions and execute the matching body. The optional else keyword is followed by a command body that is executed if no previous conditional expressions were true. The keywords then and else are optional.

Example

if {$x < 0} {
       set y 1
    } elseif {$x == 0} {
       set y 2
    } else {
       set y 3
    }

Get Tcl/Tk in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.