• §12 循环101-while循环


                            §12   循环101-while循环

                While和for具有一定的可替换性。语法如下:

    • while test body

    continue终止当次循环,break退出整个循环。

                注意while之后要用大括号来括住,用引号的话会导致只进行一次替换,导致无限循环。

    实例:

    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 "

    # 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"

    执行结果:

    x is 1

    x is 2

    x is 3

    x is 4

    exited first loop with X equal to 5

     

    x is 1

    x is 2

    x is 3

    exited second loop with X equal to 8

    存在问题:while为什么要用大括号括住 的解释还没有明白。

  • 相关阅读:
    使用shape来定义控件的一些显示属性
    Button颜色选择器进阶
    android用于打开各种文件的intent
    虚拟机操作
    二维码生成与读取
    input框只能输入整数
    实现FF背景透明,文字不透明
    打日志
    多选框
    时间戳
  • 原文地址:https://www.cnblogs.com/hfyfpga/p/4255176.html
Copyright © 2020-2023  润新知