Loop structures: Difference between revisions
Content added Content deleted
(→[[C]]: Removed syntax highlighting) |
(→[[PHP]]: Removed syntax highlighting) |
||
Line 568: | Line 568: | ||
===while=== |
===while=== |
||
<highlightSyntax> |
|||
while(ok()) { |
while(ok()) { |
||
foo(); |
foo(); |
||
Line 574: | Line 573: | ||
baz(); |
baz(); |
||
} |
} |
||
</highlightSyntax> |
|||
===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]]== |