next up previous
Next: Tcl Parsing and Up: Tcl: A Generic Previous: Syntax Summary

Tcl Example


    proc power {base p} {
        set result 1
        while {$p > 0} {
            set result [expr $result * $base]
            set p [expr $p - 1]
        return $result

Now provide a textual user interface to power ...

    set cont "y"
    while {$cont == "y" || $cont == "Y"} {
        puts "Enter base: "
        gets stdin base
        puts "Enter power: "
        gets stdin p
        puts "$base ^ $p = [power $base $p]"
        puts "Continue? (yn): "
        gets stdin cont

CS488/688: Introduction to Interactive Computer Graphics
University of Waterloo
Computer Graphics Lab