<html>
<head>
<title>A Simple Page</title>
</head>
<body>
<?php

$x = 0;
while ($x < 10)
{
$x++;
echo "  ".$x;
continue;
print("You never see this!");
}
?>

</body>
</html>
Example:

continue within a for loop

Reslult:

Staff member: grace Staff member: doris Staff member: gary Staff member: nate Staff member: tom
<?php
$usernames = array("grace","doris","gary","nate","missing","tom");
for ($x=0; $x < count($usernames); $x++) {
if ($usernames[$x] == "missing") continue;
echo "Staff member: $usernames[$x] <br />";
}
?>

Example:

Result:

100/-3 -33.333333333333 100/-2 -50 100/-1 -100 Skipping to avoid division by zero. 100/1 100 100/2 50 100/3 33.333333333333 100/4 25 100/5 20 100/6 16.666666666667 100/7 14.285714285714 100/8 12.5 100/9 11.111111111111

Using continue instead of break
<?php

$counter=-3;

for (;$counter<10;$counter++){
if ($counter==0){
echo “Skipping to avoid division by zero.<br>”;
continue;
}

echo “100/$counter “,100/$counter,”<br />”;
}

?>

0 comments:

Post a Comment

 
Top
Blogger Template