more with looping control flow bits

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

@ -1,23 +1,39 @@
<pre> <!DOCTYPE html>
<?php <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) { while ($c < 5) {
print $c++ . "\n"; print $c++ . "\n";
} }
?> ?></pre>
</pre>
<pre> <pre><?php
<?php
$myname = "Fred"; $myname = "Fred";
$i = 0; $i = 0;
while ($myname != "Rumpelstiltskin") { while ($myname != "Rumpelstiltskin") {
print $i++ . ": "; print $i++ . ": ";
if ($myname == "Fred") { if ($myname == "Fred") {
@ -26,9 +42,51 @@ while ($myname != "Rumpelstiltskin") {
$myname = "Rumpelstiltskin"; $myname = "Rumpelstiltskin";
} }
print "$myname\n"; 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";
}
print "How did you know?\n"; ?></pre>
?> </body>
</pre> </html>

Loading…
Cancel
Save