tcltk -1

puts


puts "Hello, World - In quotes"    ;# This is a comment after the command.
# This is a comment at beginning of a line
puts {Hello, World - In Braces}
puts {Bad comment syntax example}   # *Error* - there is no semicolon!
puts "This is line 1"; puts "this is line 2"
puts "Hello, World; - With  a semicolon inside the quotes"
# Words don't need to be quoted unless they contain white space:
puts HelloWorld


set
set X "This is a string"
set Y 1.24
puts $X
puts $Y
puts "..............................."
set label "The value in Y is: "
puts "$label $Y"


while
set x 1
# This is a normal way to write a Tcl while loop.
while {$x < 5} {
    puts "x is $x"
    set x [expr {$x + 1}]
}

for start test next body
for {set i 0} {$i < 10} {incr i} {
    puts "I inside first loop: $i"
}


proc name args body
proc sum {arg1 arg2} {
    set x [expr {$arg1 + $arg2}];
    return $x
}
puts " The sum of 2 + 3 is: [sum 2 3]\n\n"


lsearch list pattern
    Searches list for an entry that matches pattern, and returns the index for the first match, or a -1 if there is no match. By default, lsearch uses "glob" patterns for matching. See the section on globbing.
lsort list
    Sorts list and returns a new list in the sorted order. By default, it sorts the list into alphabetic order. Note that this command returns the sorted list as a result, instead of sorting the list in place. If you have a list in a variable, the way to sort it is like so: set lst [lsort $lst]
lrange list first last
    Returns a list composed of the first through last entries in the list. If first is less than or equal to 0, it is treated as the first list element. If last is end or a value greater than the number of elements in the list, it is treated as the end. If first is greater than last then an empty list is returned.

posted @ 2010-11-30 22:22  greencolor  阅读(189)  评论(0编辑  收藏  举报