Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1 KB

25.md

File metadata and controls

45 lines (34 loc) · 1 KB

Perl - do-while循环

原文: https://beginnersbook.com/2017/02/perl-do-while-loop-with-example/

在上一个教程中,我们讨论了while循环。在本教程中,我们将讨论 Perl 中的do-while循环。do-while循环类似于while循环,但是它们之间存在差异:在while循环中,在执行循环体之前评估条件,但是在执行循环体之后评估do-while循环条件。

do-while循环的语法:

do
{
   statement(s);
} while(condition);

执行循环的流程

首先,循环内的语句执行,然后条件得到评估,如果条件返回true,则控制流转移到do,否则它会在do-while之后跳转到下一个语句。

#!/usr/local/bin/perl

$num = 90;
do{
 $num++;
 printf "$num\n";
}while( $num < 100 );

输出:

91
92
93
94
95
96
97
98
99
100