下载此文档

第2章 Tcl与OTcl NS.ppt


文档分类:医学/心理学 | 页数:约27页 举报非法文档有奖
1/27
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/27 下载此文档
文档列表 文档介绍
第2章_Tcl与OTcl___NS
Tcl和OTcl
第 2 章
Tcl命令格式
变量
组合和替代
数学运算
过程
流程控制命令
注释
数组
OTer from Earth, nor from Venus."
}
set temp 95
if {$temp < 80} {
puts "It's a little chilly."
} else {
puts "Warm enough for me."
}
執行方法:
ns
執行的結果:
I feel right at home.
Warm enough for me.
switch
Example:()
set num_legs 4
switch $num_legs {
2 {puts "It could be a human."}
4 {puts "It could be a cow."}
6 {puts "It could be an ant."}
8 {puts "It could be a spider."}
default {puts "It could be anything."}
}
执行方法:
ns
执行結果:
It could be a cow.
for
Example :()
for {set i 0} {$i < 5} {incr i 1} {
puts "In the for loop, and i = $i"
}
执行方法:
ns
执行結果:
In the for loop, and i == 0
In the for loop, and i == 1
In the for loop, and i == 2
In the for loop, and i == 3
In the for loop, and i == 4
while
Example : ()
set i 0
while {$i < 5} {
puts "In the while loop, and i == $i"
incr i 1
}
执行方法:
ns
执行結果:
In the while loop, and i == 0
In the while loop, and i == 1
In the while loop, and i == 2
In the while loop, and i == 3
In the while loop, and i == 4
foreach
Example:()
foreach vowel {a e i o u} {
puts "$vowel is a vowel"
}
执行方法:
ns
执行結果:
a is a vowel
e is a vowel
i is a vowel
o is a vowel
u is a vowel
注释
;#
注释一天语句的后半部分
set rate ;利息
#
在语句前加#,表示注释整行
#银行参数
多行注释用“\”
#it’s a fine day\ gentle breeze;sunny
数组
Example :()
set myarray(0) "Zero"
set myarray(1) "One"
set myarray(2) "Two"
for {set i 0} {$i < 3} {incr i 1} {
puts $myarray($i)
}
执行方法:
ns
执行结果:
Zero
One
Two
Example: ()
set person_info(name) "Fred Smith“
set person_info(age) "25"
set person_info(occupation) "Plumber"
foreach thing {name age occupation}
{
puts "$thing == $person_info($thing)"
}
执行方法

第2章 Tcl与OTcl NS 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数27
  • 收藏数0 收藏
  • 顶次数0
  • 上传人小落意
  • 文件大小404 KB
  • 时间2022-05-05