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}]

Tcl之looping的更多相关文章

  1. Tcl internal variables

    Tcl internal variables eryar@163.com 在Tcl中内置了一些变量,并赋予了一定的功能.内置变量列表如下: 变量名称 功能描述 argc 指命令行参数的个数. argv ...

  2. SDC Tcl package of Timequest

    Tcl comand Tcl Commands all_clocks all_inputs all_outputs all_registers create_clock create_generate ...

  3. Oracle数据库操作分类DDL、DML、DCL、TCL类别清单异同

    DDL Data Definition Language (DDL) statements are used to define the database structure or schema. S ...

  4. linux tcl expect 安装(转)

    linux tcl expect 安装 一.Tcl安装 1.  下载:tcl8.4.20-src.tar.gz http://www.tcl.tk/software/tcltk/downloadnow ...

  5. 为Tcl编写C的扩展库

    Tcl是一个比较简洁的脚本语言,官方地址 http://www.tcl.tk. tcl脚本加载C实现的动态库非常方便. 1. 为Tcl编写一个用C实现的扩展函数. #include <stdio ...

  6. Tcl

    Tcl(发音 tickle)是一种脚本语言.由John Ousterhout创建.TCL经常被用于快速原型开发 RAD.脚本编程.GUI编程和测试等方面. Expect Expect是 另外一种非常流 ...

  7. MySQL TCL 整理

    TCL(Transaction Control Language)事务控制语言SAVEPOINT 设置保存点ROLLBACK  回滚SET TRANSACTION

  8. TCL:使用、添加库文件

    >直接引用工具自带的库文件 通过指令: .1查看能直接调用的库文件路径 #可以查到工具默认库文件路径,一般包括回显中的路径以及回显中路径的父路径. info library #D:/Script ...

  9. TCL:表格(xls)中写入数据

    intToChar.tcl # input a number : 1 to 32 , you will get a char A to Z #A-Z:1-32 proc intToChar {int} ...

随机推荐

  1. The Evaluation of Determinant(求行列式mod一个数的值)

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...

  2. 基于.NET平台常用的框架整理(转)

    基于.NET平台常用的框架整理   分布式缓存框架: Microsoft Velocity:微软自家分布式缓存服务框架. Memcahed:一套分布式的高速缓存系统,目前被许多网站使用以提升网站的访问 ...

  3. 从尾到头打印链表——剑指Offer

    https://www.nowcoder.net/practice/d0267f7f55b3412ba93bd35cfa8e8035?tpId=13&tqId=11156&tPage= ...

  4. vim 安装插件的网站

    我在想, 怎么让vim可以 显示目录结构呢?一个目录里面的文件? vim插件的网站:http://www.vim.org/scripts/script.php?script_id=1658 原文:ht ...

  5. 为XCode 6 加入新建类模板

    用XCode 6在改动之前用XCode 5 的代码的时候突然间发现 XCode 6已经把新建带有 .xib 类的模板给删去了.而项目的新需求中又要用到新建带有 .xib 的类(用惯了~),全部不得不又 ...

  6. Spring MVC : Java模板引擎 Thymeleaf (二)

    本文原计划直接介绍Thymeleaf的视图解析,但考虑到学习的方便,决定先构建一个spring-mvc. 以下的全部过程仅仅要一个记事本和JDK就够了. 第一步,使用maven构建一个web app. ...

  7. 5分钟APIG实战: 使用Rust语言快速构建API能力开放

    序言:Rust语言简介 参与过C/C++大型项目的同学可能都经历过因为Null Pointer.Memory Leak等问题“被” 加班了不知道多少个晚上.别沮丧,你不是一个人,Mozilla Fir ...

  8. 使用VS2005安装和编译QT4.53源码

    学习Qt,当然是QT4好.可是装了4.86以后,网上下载的书中的例子大多无法直接用VS执行(个人不喜欢用QT Creator),即打开pro转换的时候出错(我也懒的研究为什么出错了).看了一下发布时间 ...

  9. Kubernetes——自动扩展容器!假设你突然需要增加你的应用;你只需要告诉deployment一个新的 pod 副本总数即可

    参考:http://kubernetes.kansea.com/docs/hellonode/ 现在你应该可以通过这个地址来访问这个service: http://EXTERNAL_IP:8080 或 ...

  10. go语言笔记——数组长度不可变,但是元素值是可变的!!!

    数组声明的格式是: var identifier [len]type 例如: var arr1 [5]int 在内存中的结构是: 对索引项为 i 的数组元素赋值可以这么操作:arr[i] = valu ...