Bug #71262 [Com]: for loop error

From: Date: Fri, 08 Jan 2016 11:11:08 +0000
Subject: Bug #71262 [Com]: for loop error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198514@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71262&edit=1 ID: 71262 Comment by: php at duncanc dot co dot uk Reported by: m dot dziczkowski at prokonto dot pl Summary: for loop error Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 5.6.4 Block user comment: N Private report: N New Comment: Your example is flawed, the second "not working" loop will not loop because $y is never "less than or equal to" 1945, it starts off at 2015. I think you meant to do: for ($y = 2015; $y >= 1945; $y--) { // some code to do } Previous Comments: ------------------------------------------------------------------------ [2016-01-02 07:06:32] requinix@php.net > for ($y = 2015; $y <= 1945; $y--) $y starts at 2015. 2015 <= 1945 is false. Loop exits immediately. You want > for ($y = 2015; $y >= 1945; $y--) ------------------------------------------------------------------------ [2016-01-02 06:59:16] m dot dziczkowski at prokonto dot pl /* The select bellow don't shows other options then "-- select --" */ // code trunchated for securuty reasons <select name = "year"> <option value = "#">-- Select --</option> <? for ($y = 2015; $y <= 1945; $y--) { echo "<option value = \"$y\">$y</option>"; } ?> </select> /* When I done a small change into: */ <select name = "year"> <option value = "#">-- Select --</option> <? for ($y = 1945 $y <= 2015; $y++) { echo "<option value = \"$y\">$y</option>"; } ?> </select> /* the code started to work */ ------------------------------------------------------------------------ [2016-01-02 02:27:51] stas@php.net Please provide full code, expected and actual output and explain what you mean by "not working". ------------------------------------------------------------------------ [2016-01-02 02:21:44] m dot dziczkowski at prokonto dot pl Description: ------------ I had found a bug in the for loop. Increasing value is working, but decreasing isn't. See code Test script: --------------- // Working for ($y = 1945; $y <= 2015; $y++) { // some code to do } // Not working for ($y = 2015; $y <= 1945; $y--) { // some code to do } // sames happens if I replace (in the not working one) the "2015" with a variable (for example: $year = 2015; or $year = date("Y"); Expected result: ---------------- displayed values from 2015 to 1945 Actual result: -------------- none ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71262&edit=1

« previous php.bugs (#198514) next »