zoukankan      html  css  js  c++  java
  • PHP 循环- While循环

    PHP几种循环如下

    • while - 只要制定的条件成立,则循环执行代码快
    • do...while - 首先执行一次代码快,然后在制定的条件成立时重负这个循环
    • for - 循环代码块的制定的次数
    • foreach - 根据数组中每个元素来循环代码块

    PHP - While语句

    while循环执行重复的代码块,直到指定的条件不成立

    语法:

    while (){
            //要执行的代码;  
    }

    实例:

    <?php
    $i=1;
    while($i<=5)
    {
        echo "The number is " . $i . "<br>";
        $i++;
    }
    ?>
    

    输出:
    The number is 1
    The number is 2
    The number is 3
    The number is 4
    The number is 5

    PHP - do...while语句

    do...while 语句会至少执行一次代码,然后检查条件,只要条件成立,就会重复进行循环。

    语法:

    do
    {
        要执行的代码;
    }
    while (条件);
    

    实例:

    <?php
    $i=1;
    do
    {
        $i++;
        echo "The number is " . $i . "<br>";
    }
    while ($i<=5);
    ?>
    

    输出:

    The number is 2
    The number is 3
    The number is 4
    The number is 5
    The number is 6

     

  • 相关阅读:
    hdoj-1004-Let the Balloon Rise(水题)
    hdoj-1827-Summer Holiday(scc+缩点)
    poj--3624--Charm Bracelet(动态规划 水题)
    HDU
    HDU
    HDU
    HDU
    【POJ1654】Area【叉积】
    【POJ1654】Area【叉积】
    【SSLOJ1715】计算面积【叉积】
  • 原文地址:https://www.cnblogs.com/shiyoushao/p/7986804.html
Copyright © 2011-2022 走看看