note 33900 added to control-structures.while
| From: | Merve at rack1 dot php dot net | Date: | Thu, 10 Jul 2003 14:49:20 +0000 |
| Subject: | note 33900 added to control-structures.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51850@lists.php.net to get a copy of this message | ||
This is an easy way for all you calculator creators to make it do factorials. The code is this:
<?php
$c = ($a-1);
$d = $a;
while ($c>=1)
{
$a = ($a*$c);
$c--;
}
print (" $d! = $a");
?>
$a changes, and so does c, so we have to make a new variable, $d, for the end statement.
----
Manual Page -- http://www.php.net/manual/en/control-structures.while.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33900
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33900&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33900&report=yes