Table of Contents

Getting started with Tcl: example 7

This page is part of the Airplug documentation related to Tcl/Tk.
Back to the Tcl/Tk documentation page / Back to the Airplug documentation page

Creating procedures

Script

#!/usr/bin/tclsh
# procedures, while
 
set Chaine {bonne année}
puts stdout $Chaine

# Defining a procedure. Beware of spaces and brackets.
proc fact { nb } {
    global Chaine
    puts stdout "Chaine dans la procédure = $Chaine"
 
    set i [expr $nb - 1]
    while { $i > 0 } { # Beware of spaces and brackets
	set nb [expr $nb * $i]
	set i [expr $i - 1]
    }
    return $nb
}
 
puts stdout ""

# Calling the procedure
puts stdout "factoriel 5 = [fact 5]"

Output

bonne année
 
Chaine dans la procédure = bonne année
factoriel 5 = 120

<br/>


This page is part of the Airplug documentation related to Tcl/Tk.
Back to the Tcl/Tk documentation page / Back to the Airplug documentation page