zoukankan      html  css  js  c++  java
  • §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为什么要用大括号括住 的解释还没有明白。

  • 相关阅读:
    【Android
    【数据结构】之链表(C语言描述)
    【数据结构】之顺序表(C语言描述)
    【Android
    【Android
    【Android
    【Android
    【Android
    在线HTTP速度测试(响应时间测试)及浏览器兼容测试
    阿里云 腾讯云 服务器挂载数据盘
  • 原文地址:https://www.cnblogs.com/hfyfpga/p/4255176.html
Copyright © 2011-2022 走看看