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. [bzoj1084][SCOI2005]最大子矩阵(DP)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1084 分析: m=1时:相当于只有一行数,让你取出p段,使得总和最大 明显可以DP,f ...

  2. 用xtrabackup+binlog恢复误删除的数据库

    关键技术,数据库产生的二进制文件,在主库就是binlog在从库就是relay-log,用最新的物理备份可以新启动个新实例,可以模拟个从库,把主库的binlog复制到新的数据库实例上,利用主从复制和物理 ...

  3. Hive之内置函数

    函数分类 UDF(User Defined Function):数据一对一 UDAF(User Defined Aggreation Function):数据多对一 UDTF(User Defined ...

  4. oracle em 5500访问问题

    oracle em 5500访问问题 需要加s了:https://127.0.0.1:5500/em/

  5. 【打CF,学算法——二星级】CF 520B Two Buttons

    [CF简单介绍] 提交链接:Two Buttons 题面: B. Two Buttons time limit per test 2 seconds memory limit per test 256 ...

  6. pymysql 本地不抱错 连接云数据库报错

    import pymysql h, pt, u, p, db = 'rm-2zeoye0j3957bw1w2.mysql.rds.aliyuncs.com', 3306, 'tongji_2017', ...

  7. AngularJS2.0 一个表单例子——总体说来还是简化了1.x 使用起来比较自然

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. LaTeX 在线编辑器(LaTeX online editors)

    eqneditor:有强大的几乎所有常用的数学符号对应的图标形式,便于快速完成latex公式编辑且易于粘贴拷贝. 此外,更为重要的一点是,随着编辑窗口内公式的编辑,会在页面的底部,自动生成其对应的 h ...

  9. Java Swing Action 动作

    Swing包提供了一种非常实用的机制来封装命令,并将它们连接到多个事件源,这就是Action接口.一个动作是一个封装下列内容的对象: × 命令的说明(一个文本字符串和一个可选图标): × 执行命令所需 ...

  10. C# Pen绘制虚线(System.Drawing.Pen与System.Windows.Media.Pen)

    一.绘制虚线的方法 GDI绘制,使用的是System.Drawing.Pen Pen pen = new Pen(Color.Red, 1);            pen.DashStyle = S ...