1  While loop

while  test  body

  The while command evaluates test as an expression. If test is true, the code in body is executed. After body has been executed, test is evaluated again.

Example:

 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}]
} puts "exited first loop with X equal to $x\n" # The next example shows the difference between ".." and {...}
# How many times does the following loop run? Why does it not
# print on each pass? set x 0
while "$x < 5" {
set x [expr {$x + 1}]
if {$x > 7} break
if "$x > 3" continue
puts "x is $x"
} puts "exited second loop with X equal to $x"

2  For and incr

for  start  test  next  body

  During evaluation of the for command, the start code is evaluated once, before any other arguments are evaluated. After the start code has been evaluated, the test is evaluated. If the test evaluates to true, then the body is evaluated, and finally, the next argument is evaluated. After evaluating the next argument, the interpreter loops back to the test, and repeats the process. If the test evaluates as false, then the loop will exit immediately.

incr  varName ?increment?

  This command adds the value in the second argument to the variable named in the first argument. If no value is given for the second argument, it defaults to 1.

Example:

 for {set i 0} {$i < 10} {incr i} {
puts "I inside first loop: $i"
} for {set i 3} {$i < 2} {incr i} {
puts "I inside second loop: $i"
} puts "Start"
set i 0
while {$i < 10} {
puts "I inside third loop: $i"
incr i
puts "I after incr: $i"
} set i 0
incr i
# This is equivalent to:
set i [expr {$i + 1}]

最新文章

  1. HDU 4833 Best Financing (DP)
  2. js中设置元素class的三种方法小结
  3. Java Executor并发框架(一)整体介绍
  4. docker的四种网络模式
  5. Redis与Memcached对比
  6. 从无到有开发连麦直播技术&lt;转&gt;
  7. 转:Linux中find命令-path -prune用法详解
  8. NodeJS中的http模块
  9. [JCIP笔记] (三)如何设计一个线程安全的对象
  10. [NOI2011]道路修建
  11. IFE第二天
  12. cadence16.6 暴力破解出现再次安装出现问题为Sever-----------问题
  13. 20190407 Word合并单元格
  14. jQueryValidate的表单提交ajax刷新代码
  15. 计算几何总结(Part 1~2)
  16. 网络管理命令ping和arping
  17. 小学四则运算APP 第一阶段冲刺 第二天-补
  18. 基于ngx_lua的动态服务路由方案
  19. C++ template —— 模板中的名称(三)
  20. sql_server角色成员身份权限

热门文章

  1. 洛谷—— P1657 选书
  2. 源码分析-react1-根节点渲染
  3. spring mvc日期转换(前端到后端,后端到前端)
  4. ASPNET Razor 使用 @Ajax.BeginForm 需要注意到的细节
  5. *** + Polipo 配置全局代理(Linux 版本)
  6. UltraEdit UE如何设置自动换行
  7. 玩转iOS开发 - 视图控制器生命周期
  8. Python&amp;amp;MySQL
  9. struts2 全局拦截器,显示请求方法和參数
  10. 适合国内网速的CDH5安装