PHP Classes
elePHPant
Icontem

Loops are not equivalent to Iterators

Recommend this page to a friend!

      PHP Classes blog  >  You have doing PHP it...  >  All threads  >  Loops are not equivalent to Iterators  >  (Un) Subscribe thread alerts  
Subject:Loops are not equivalent to Iterators
Summary:Poorly written, inaccurate and misleading
Messages:4
Author:Stefan Jibrail Froelich
Date:2016-10-12 08:46:51
Update:2016-10-12 21:29:25
 

 


  1. Loops are not equivalent to Iterators   Reply   Report abuse  
Stefan Jibrail Froelich - 2016-10-12 08:54:21
It pains me to say this, but this article is not only poorly written, it's not properly researched and misleading as well.

Iterators do not replace loops. Iterators are used in loops.
A simple example foreach. It manages the Iterator by calling the necessary methods such as next().

In order to iterate, you can manually call next() on your Iterator but that means you can only process a set number of items.

This article demonstrates a poor knowledge of what loops are.

A loop simple means, do this thing a number of times until my condition is met. In many cases, this means, go through all the data in my structure until all items are processed.

Yes, iterators do make your life easier especially when you need to do some complex stuff like filter, or as in the article nest iterations, but they are NOT a replacement for loops.

And btw, generators are not a way to iterate. They are a lazy way to (as the name suggests), generate data.

I would point you to both my articles on iterators and generators on sitepoint but that's not allowed on this site.

  2. Re: Loops are not equivalent to Iterators   Reply   Report abuse  
Manuel Lemos - 2016-10-12 08:57:59 - In reply to message 1 from Stefan Jibrail Froelich
There may seem to be a misunderstanding. There is nothing disallowing you to point to your articles in Sitepoint or any other site.

Actually, this article points to another article in Sitepoint, in case you have not noticed it at the end.

  3. Re: Loops are not equivalent to Iterators   Reply   Report abuse  
Stefan Jibrail Froelich - 2016-10-12 20:42:47 - In reply to message 2 from Manuel Lemos
My apologies. I just remembered it was when I tried to recommend a package not on PHPClasses.

  4. Re: Loops are not equivalent to Iterators   Reply   Report abuse  
Manuel Lemos - 2016-10-12 21:29:25 - In reply to message 3 from Stefan Jibrail Froelich
Oh, I see what you mean. You are right.

The recommendation system is meant to help developers getting more visibility for their packages published in the site.

Nowadays package recommendations even appear on the site search results.

That is why links to other sites are not allowed on the package recommendations.

Anyway, you can put links to any other sites in blog posts, comments, package pages, etc..