php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15064 for loops do not work properly (is it a feature or a bug?)
Submitted: 2002-01-16 03:01 UTC Modified: 2002-01-16 03:11 UTC
From: nohn@php.net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.1.1 OS: Windows NT 4
Private report: No CVE-ID: None
 [2002-01-16 03:01 UTC] nohn@php.net
for ($i=1; $i==20; $i++) {
  echo($i);
}

does not work, while

for ($i=1; $i>=20; $i++) {
  echo($i);
}

works fine. of course, if the first statement would work it wourld be redundant, so my questions is: is it a feature or a bug?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-16 03:05 UTC] yohgaki@php.net
This is not bug.
Most language behave as PHP does.
 [2002-01-16 03:11 UTC] torben@php.net
Check the manual; this is the way for loops work:

From page http://www.php.net/manual/en/control-structures.for.php

  for (expr1; expr2; expr3) statement

  The first expression (expr1) is evaluated (executed) once 
  unconditionally at the beginning of the loop.

  In the beginning of each iteration, expr2 is evaluated. If 
  it evaluates to TRUE, the loop continues and the nested 
  statement(s) are executed. If it evaluates to FALSE, the 
  execution of the loop ends.

  At the end of each iteration, expr3 is evaluated   
  (executed).



Hope this helps,

Torben
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 10:01:38 2025 UTC