I have a for loop, with a $count of 23.
for($page=0; $page < $count; $page++) {
echo $page;
}
What I want to do is instead of increasing the page variable by one, I want to do it by 10 so that when $page is echoed it I want the results to be 10, 20, and not go past 23.
for($page=0; $page < $count; $page+10) {
echo $page;
}
When I do this, the loop continues infinitely, echoing 0. IF anyone has any advice, I would really appreciate it. Thanks in advance.
Just got your increment syntax a bit wrong (should have been page
+=not page+which doesn’t actually update the value of the$pagevar)Alternatively you can use the long form/more complex mathematics:
word of caution make sure you stick with a ranged condition (
<or<=) if you’re switching your step size like this, otherwise you can jump past your condition (if it read!=23for example) and create a never ending loop. Not a problem for you the way you wrote it, but just something to consider.