Use integer to control a while loop in PHP

Description

The following code shows how to use integer to control a while loop.

Example


/* www .j av  a  2  s.  co  m*/
<?php

$widgetsLeft = 10;

while ( $widgetsLeft > 0 ) {
  echo "Selling a widget... ";
  $widgetsLeft--;
  echo "done. There are $widgetsLeft widgets left.<br />";
}

echo "We're right out of widgets!";

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition