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.

转载于:https://www.cnblogs.com/greencolor/archive/2010/11/30/1892492.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值