加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Learning Perl: 10.2. The until Control Structure

发布时间:2020-12-15 20:55:38 所属栏目:大数据 来源:网络整理
导读:? 10.2. The until Control Structure Sometimes,you'll want to reverse the condition of a while loop. To do that,use until : until ($j $i) { $j *= 2; } This loop runs until the conditional expression returns true. It's really just a while lo

Previous Page

Next Page

?

10.2. The until Control Structure

Sometimes,you'll want to reverse the condition of a while loop. To do that,use until:

    until ($j > $i) {
      $j *= 2;
    }

This loop runs until the conditional expression returns true. It's really just a while loop in disguise,except it repeats as long as the conditional is false,rather than true. The conditional expression is evaluated before the first iteration,so this is a zero-or-more-times loop,just like the while loop.[*] As with if and unless,you could rewrite any until loop to become a while loop by negating the condition. But generally,you'll find it simple and natural to use until from time to time.

[*] Pascal programmers,take note: in Pascal,the repeat-until always runs at least one iteration,but an until loop in Perl may not run at all if the conditional expression is true before the loop starts.

Previous Page

Next Page

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读