How many times was I forced to write this ugly construct...
Code: Select all
for ($i = 1; $i <= 10; $i++) {
echo $i;
}Code: Select all
for (10) {
echo $i;
}Code: Select all
for ([number of iterations]) {
statement(s);
}
Code: Select all
for ($i = 1; $i <= 10; $i++) {
echo $i;
}Code: Select all
for (10) {
echo $i;
}Code: Select all
for ([number of iterations]) {
statement(s);
}
Code: Select all
for i := 1 to 10 do ... Code: Select all
for (10) {
echo $i;
}Oh yes, I had forgotten about that. Yep, a variable must be definable.Pagat wrote:i also don't like the "common" syntax for for loops. But i guess that's because i started with the Pascal/Delphi way of doing things where it is:.Code: Select all
for i := 1 to 10 do ...
in your example:would $i be a "standard" variable in such for loops? Because we would definitely need a variable of some kind in the loop. And if it's hardcoded it could conflict with a variable outside of the loop. So you should at least give the option to let the user define an own loop-variable name.Code: Select all
for (10) { echo $i; }
TheQwerty wrote:Eh... I don't know why you hate the normal syntax, but I think there's a reason so many languages use it.
Only being able to define the number of iterations takes a lot of the functionality of a for loop away.
You can't define a different starting number.
You can't change the direction.
You can't change the increment/decrement amount so it isn't too useful to do something to every odd/even/third item.
It's a much cleaner interface for anything that requires some type of index, even if you're not breaking based on that index's value.
I think if you implemented it with only an iterations value, I'd still be cursing you every time I used this.
Why don't implement both versions, I think the shorten one can be very usefull, but the normal version has advantages too.admin wrote:Anyway, the normal For syntax looks to me like an obsessive one-liner. You can do all you mentioned very easily using a While loop. Actually, having While, I don't see a good reason adding a For loop at all (apart from that users might expect to have it).