more with looping control flow bits

cat-town
Dan Buch 14 years ago
parent b39eaef485
commit 3970fead8f

@ -1,34 +1,92 @@
<pre>
<?php
<!DOCTYPE html>
<html>
<head>
<title>looping!</title>
<style type="text/css">
/*<![CDATA[*/
$c = 0;
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";
}
while ($c < 5) {
print $c++ . "\n";
}
?></pre>
?>
</pre>
<pre><?php
<pre>
<?php
$menu = array(
"Toast and Jam",
"Bacon and Eggs",
"Homefries",
"Skillet",
"Milk and Cereal"
);
$myname = "Fred";
$i = 0;
$count = count($menu);
while ($myname != "Rumpelstiltskin") {
print $i++ . ": ";
for ($i = 0; $i < $count; $i++) {
$j = $i + 1;
if ($myname == "Fred") {
$myname = "Leslie";
} else {
$myname = "Rumpelstiltskin";
print "$j. {$menu[$i]}\n";
}
print "$myname\n";
}
print "How did you know?\n";
?></pre>
?>
</pre>
</body>
</html>

Loading…
Cancel
Save