Perl until 循环

Perl 教程 · 2019-02-26 21:26:32

until 语句在给定条件为 false 时,重复执行语句或语句组。

语法

语法格式如下所示:

until(condition)
{
   statement(s);
}

在这里,statement(s) 可以是一个单独的语句,也可以是几个语句组成的代码块。

condition 可以是任意的表达式,当条件为 false 时执行循环。 当条件为 true 时,程序流将继续执行紧接着循环的下一条语句。

流程图

Perl 中的 until 循环

图表中,until 循环的关键点是循环可能一次都不会执行。当条件为 true 时,会跳过循环主体,直接执行紧接着 while 循环的下一条语句。

实例

#!/usr/bin/perl $a = 5; # 执行 until 循环 until( $a > 10 ){ printf "a 的值为 : $a\n"; $a = $a + 1; }

程序中在变量 $a 小于 10 时执行循环体,在变量 $a 大于 10 时,退出循环。

执行以上程序,输出结果为:

a 的值为 : 5
a 的值为 : 6
a 的值为 : 7
a 的值为 : 8
a 的值为 : 9
a 的值为 : 10

点击查看所有 Perl 教程 文章: https://codercto.com/courses/l/19.html

查看所有标签

Distributed Algorithms

Distributed Algorithms

Wan Fokkink / The MIT Press / 2013-12-6 / USD 40.00

This book offers students and researchers a guide to distributed algorithms that emphasizes examples and exercises rather than the intricacies of mathematical models. It avoids mathematical argumentat......一起来看看 《Distributed Algorithms》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具