Procedures return to the calling program through "return" statement
Every procedure must have a corresponding return statement. This however is not strictly required.
Once they are created, procedures could be used just as any other TCL command
Procedures are declared with the help of keyword "proc "
Each procedure may have a set of formal parameters and some variables - local and global
Syntax:
statement1
statement2
:
}
Example:
}
Syntax:
Example:
% proc proc_a { a b c } { body of procedure }
% proc proc_b b { body of procedure }
Once created, a procedure could be invoked/ called just by its name
Example: proc_a { $a $b $c } , proc_b { $b } w.r.t. The above example
Every procedure has its own set of local variables.
Any two procedures may have variables with the same names. The values of the variables do not get affected since they are not visible outside the procedure block.
"global " could be used to declare the scope of some variables as global
"global " should be used inside a procedure
Syntax:
"global " binds variable names "varName "... to global variables. References to these names will refer to global variables instead of local variables for the duration of the current procedure.
Example 1:
Example 2: Simple tree traversal iterative procedure.
Example 3 :
Example 3 :
No comments:
Post a Comment