Page 72 - Open Soource Technologies 304.indd
P. 72
Web Technologies-I
Notes For instance, we could use it to modify a previous do ... while statement. In the following example,
the code will now terminate if the value to be processed is not an integer.
$x = 0;
$rVal = “”;
do {
if (isset($aName[$x])) {
if (is_int($aName[$x])) {
$rVal = “Bad Value”;
break;
}
$bName[$x] = someProc($aName[$x]);
}
$x++;
}
while (isset($aName[$x]));
3.4.2 Continue Statement
If you are using an iterative statement and do not want to terminate it, just skip the current instance
or iteration, you can use the continue statement. Continue says that the current iteration is done
and the next one should be started. This is useful if the statement block has multiple possible
exit points.
$x = 0;
$y = 0;
$rVal[0] = “”;
do {
if (isset($aName[$x])) {
if (is_int($aName[$x])) {
$rVal[$y] = “Bad Value at $aName[$x]”;
$x++;
$y++;
continue;
}
$bName[$x] = someProc($aName[$x]);
}
$x++;
}
The following code is missing a single line compared to the one before it and is in error that will
probably generate an infinite loop. This is because if it hits continue, it does not increment the
66 LOVELY PROFESSIONAL UNIVERSITY