box-o-sand/docroot/html/loops.php
2010-12-29 21:43:03 -05:00

93 lines
1.2 KiB
PHP

<!DOCTYPE html>
<html>
<head>
<title>looping!</title>
<style type="text/css">
/*<![CDATA[*/
pre {
border: 1px dashed #777;
color: #222;
background: #fefefe;
padding: 5px;
margin: 10px;
}
/*]]>*/
</style>
</head>
<body>
<pre><?php
$c = 0;
while ($c < 5) {
print $c++ . "\n";
}
?></pre>
<pre><?php
$myname = "Fred";
$i = 0;
while ($myname != "Rumpelstiltskin") {
print $i++ . ": ";
if ($myname == "Fred") {
$myname = "Leslie";
} else {
$myname = "Rumpelstiltskin";
}
print "$myname\n";
}
print "How did you know?\n";
?></pre>
<pre><?php
$c = 6;
do {
print "Hi\n";
} while ($c < 5);
?></pre>
<pre><?php
for ($i = 0; $i < 5; $i++) {
print "$i\n";
}
?></pre>
<pre><?php
$menu = array(
"Toast and Jam",
"Bacon and Eggs",
"Homefries",
"Skillet",
"Milk and Cereal"
);
$count = count($menu);
for ($i = 0; $i < $count; $i++) {
$j = $i + 1;
print "$j. {$menu[$i]}\n";
}
?></pre>
</body>
</html>