A test

need print:1 4 7 10 13 16 19 22 25,

for($i=1;$i<=9;$i=_____){//fill the blank
echo $i;
}What do you want to happen? I can see that you want to add 3 and echo the result. But do you want it done 9 times or do you want it while the value is lower than some value? Depending on how you want it you can do any of these ways:

for ($i = 1; $i <= 9; $i = $i + 3) {
echo $i;
}

for ($i = 0; $i < 9; $i++) {
echo $i * 3 + 1;
}I think it's not wrong,
but have answer to this.<?
$intMinimum = 1;
$intMaximum = 25;
$intSkip = 3;
for($intI = $intMinimum; $intI <= $intMaximum; $intI = $intI + $intSkip) {
echo $intI . '<br />' . "\n";
}
?>


Or even better...


<?
$intMinimum = 1;
$intMaximum = 25;
$intSkip = 3;
$intMinimum = min($intMinimum, $intMaximum);
$intMaximum = max($intMinimum, $intMaximum);
$intSkip = abs($intSkip);
for($intI = $intMinimum; $intI <= $intMaximum; $intI = $intI + $intSkip) {
echo $intI . '<br />' . "\n";
}
?>Or
foreach(range(1,25,3) as $i)
{
...
}a answer to this


<?php
for($i=1;$i<=9;$i=10,printf(" 4 7 10 13 16 19 22 25") ){
echo $i;
}
?>Well you almost only output a string !! So PHP doesn't calculate anything (or almost !!) what's the use ?!I think it's not wrong,
but have answer to this.

It is not possible to give an answer to your first post since it is totally messed up with the value of $i. But I gave two answers that would work, and you have gotten 3 other answers as well. All those 5 answers would work without any problem IF you mean what have been answered. If not then you have to ask in a way that we can understand.

By the way, a better way to follow your way would be

<?php
echo "1 4 7 10 13 16 19 22 25";
?>

Or to just do this in the HTML code:

1 4 7 10 13 16 19 22 25
 
Back
Top