Loop structures: Difference between revisions

Content added Content deleted
m (Adding syntax highlighting to PHP snippets)
Line 587: Line 587:


===do-while===
===do-while===
<highlightSyntax>

$i = 0;
$i = 0;
do {
do {
echo $i;
echo $i;
} while ($i > 0);
} while ($i > 0);
</highlightSyntax>
===for===
===for===
<highlightSyntax>

for($i = 0; $i < 10; ++$i) {
for($i = 0; $i < 10; ++$i) {
echo $i;
echo $i;
}
}
</highlightSyntax>

===foreach===
===foreach===
<highlightSyntax>

foreach(range(0, 9) as $i) {
foreach(range(0, 9) as $i) {
echo $i;
echo $i;
}
}
</highlightSyntax>

foreach is only used for arrays, which is not obvious from the above example
foreach is only used for arrays, which is not obvious from the above example
<highlightSyntax>

foreach($array as $key => $value) {
foreach($array as $key => $value) {
echo $key.' is '.$value;
echo $key.' is '.$value;
}
}
</highlightSyntax>


==[[PostScript]]==
==[[PostScript]]==