Create a loop for a specific number of iterations, *without* a variable?

As a replacement for a ‘for’ loop, maybe.

Depends on how long it takes for the function to become universally available. Writing redistributable software kind of limits using new stuff (loop(), closures etc).

Maybe this is what you meant, but why not go all out and invent a new type of loop (rather than a function)? (:


loop (3) {
    // Do awesome stuff 3 times
}

If it was there to use… maybe. :slight_smile:

Well, this would be my first contribution and the addition of an extra function should be an easy point of entry.

Should.

Unless you think otherwise?

Off Topic:

Whilst I have your attention Peter, nice work on the SPL getExtension addition. :wink:

In terms of adding a new language construct versus a function, without having dealt with PHP itself before (I don’t know, have you?) both would be as frustrating and annoying (and, in hindsight, likely very simple ;)) to implement. If I was pushed to choose one or t’other, I would think the new loop construct would be the easier and most sensible choice.

I would question whether folks would be willing to accept a new loop construct but can say that they most probably won’t accept a magical function that returns TRUE n times. That said, implementing either (or maybe both!) would be a good educational experience if you’re looking into what makes up the guts of the language.

If you’re looking for things to do, it might also be worth taking a look through the todo list on the wiki and/or the [url=http://bugs.php.net/search.php?order_by=ts1&direction=DESC&cmd=display&status=Open&bug_type=All&package_name%5B%5D=Feature%2FChange+Request]open feature requests.

[ot] > Whilst I have your attention Peter, nice work on the SPL getExtension addition. :wink:

Thanks. Using pathinfo() got really annoying, so I had to scratch the itch.[/ot]

If it’s to go through an array, possibly something like:

<?php

// Array to iterate through
$fruits = array("orange", "banana", "apple", "raspberry");

while (!empty($fruits)) {
    $fruit=array_pop($fruits);
    echo "<p>$fruit</p>";
}
?>