in reply to Re^2: while loops with two tests not working.
in thread while loops with two tests not working.

I believe it is a logic error.

The code in the while block does not execute because the while condition is false.

$average = 3; $i = 0; while ($i > 0 and $i <= $average)
In order for the while condition to be true, $i must be either 1, 2 or 3. But $i starts at 0.

Do you really want this?

while ($i >= 0 and $i <= $average)

Replies are listed 'Best First'.
Re^4: while loops with two tests not working.
by Eagle_f90 (Acolyte) on Jul 20, 2007 at 00:52 UTC
    I was about to say "I can't have I start at 1 or be eq to 0 since if average = 0.5 it would not produce a star for me" but then realized I have an if statement later to produce the half star I need. By setting i = 1 everything is working. For some reason I just could not see it in my head until now. Thanks.