Page 68 - Programador-PHP
P. 68

Programación Procedural de Aplicaciones Web de baja complejidad
        PHP Experto – Tomo I                                                                                                                                                  Eugenia Bahit


                       mientras que (N sea menor o igual a 5) {
                           imprimir N
                           incrementar N
                       }




        Un ejemplo práctico


          $years = array();
          $year = 1990;

          while ($year <= 2000) {
              $years[] = $year;
              $year++;
          }
          print_r($years);

          /*
          Array
          (
              [0] => 1990
              [1] => 1991
              [2] => 1992
              [3] => 1993
              [4] => 1994
              [5] => 1995
              [6] => 1996
              [7] => 1997
              [8] => 1998
              [9] => 1999
              [10] => 2000
          )
          */



        Vale la pena hacer notar, que si al iniciar una iteración con
        while,   la   primera   expresión   es   falsa,   no   se   continuará
        ejecutando el bucle:

          $years = array();
          $year = 1990;

          while ($year < 1990) {
              $years[] = $year;
              $year++;
          }
          print_r($years);



                                              68
   63   64   65   66   67   68   69   70   71   72   73