tcl的helloworld

本文介绍Tcl编程语言的基础用法,包括打印语句、变量赋值、流程控制语句及简单函数定义。通过实例展示了不同类型的puts命令使用方法,以及如何创建简单的循环和自定义过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

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 "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
puts {Bad comment syntax example} # *Error* - there is no semicolon!

输出:
Hello, World - In quotes
Hello, World - In Braces
This is line 1
this is line 2
Hello, World; - With a semicolon inside the quotes
HelloWorld
wrong # args: should be "puts ?-nonewline? ?channelId? string"
while executing
"puts {Bad comment syntax example} # *Error* - there is no semicolon!"
(file "helloworld.tcl" line 10)

--------------------------
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 {set i 0} {$i < 10} {incr i} {
puts "I inside first loop: $i"
}

------又发现搞笑代码了--魔幻语言就是让人容易误解--
proc sum {arg1 arg2} {
set x [expr {$arg1 + $arg2}];
return $x
}

puts " The sum of 2 + 3 is: [sum 2 3]\n\n"

proc for {a b c} {
puts "The for command has been replaced by a puts";
puts "The arguments were: $a\n$b\n$c\n"
}

for {set i 1} {$i < 10} {incr i}

输出:
 The sum of 2 + 3 is: 5


The for command has been replaced by a puts
The arguments were: set i 1
$i < 10
incr i


http://www.tcl.tk/man/tcl/tutorial/Tcl12.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值