1

How can I add or in for loop check? for example:

for ($i=1; ($i <= $untilPoint) or ($i <= $points); $i++){
.. code ...
}
1
  • If it doesn't work (does it?), then you could turn it into a do/while loop. Commented Aug 10, 2013 at 19:56

2 Answers 2

2

Exactly what you typed is valid PHP. For example, this program:

<?
$untilPoint = 3;
$points = 5;
for ($i=1; ($i <= $untilPoint) or ($i <= $points); $i++){
    echo("$i\n");
}
?>

prints this:

1
2
3
4
5

(tested in PHP 5.2.17, run from the Bash prompt).

That said, I wonder if maybe you really need and rather than or? If $i is an index into an array of points, where $points is the number of points and $untilPoint is an arbitrary cutoff, then you want and, not or.

Sign up to request clarification or add additional context in comments.

Comments

1

This is how it should be done, probably it runs slightly faster. You can separate with , see http://php.net/manual/en/control-structures.for.php for more information

<?
$untilPoint = 3;
$points = 5;
for ($i=1; $i <= $untilPoint, $i <= $points; $i++){
    echo($i , "\n");
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.