DEV Community

Discussion on: Which types of loops are most popular in the programming languages you use?

Collapse
 
aschwin profile image
Aschwin Wesselius

In PHP the implementation of collections is quite popular now. This makes map and reduce a breeze. It also makes it more readable.

However I am curious to know why not many people know about and have implemented a Duff’s Device.

This is probably the most optimized way of iteration over items. My take is because it is less readable or understandable.

I have implemented this approach both in JavaScript and PHP. And it is quite faster than normal iterations. I think it can be implemented in any language that supports a while loop.

However only use it where optimizations are needed.