more with looping control flow bits

This commit is contained in:
Dan Buch 2010-12-29 21:43:03 -05:00
parent b39eaef485
commit 3970fead8f

View File

@ -1,34 +1,92 @@
<pre> <!DOCTYPE html>
<?php <html>
<head>
<title>looping!</title>
<style type="text/css">
/*<![CDATA[*/
$c = 0; pre {
border: 1px dashed #777;
while ($c < 5) { color: #222;
print $c++ . "\n"; background: #fefefe;
} padding: 5px;
margin: 10px;
?>
</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"; /*]]>*/
</style>
</head>
<body>
<pre><?php
?> $c = 0;
</pre>
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>