BTW, why didn't anyone make a language with a loop construct which checks the condition in the middle of the loop? Like
{
char *pos = strchr(str, old);
} while(pos) {
*pos = new;
}
Way to reference a five-year-old thread, jerkface.
Second, this function only replaces the first occurence of the char, not all of them.
so yeah, his a retard. but the loop is infinite if old == new (and occurs in the string). and it loops until segfault on old == 0. and its inefficient.
>>3
A question for the ages. The “n + ½” loop pattern was recognized as early as 1967, see Wirth's “On certain basic concepts of programming languages”1 and Knuth's “Structured Programming with Goto Statements”2. The reason one of the suggested solutions wasn't broadly adopted is probably that existing syntax like break and sequencing in the condition is not that bad.
>>9
I remember reading about Knuth asking that question. Thanks for the literature!
Yeah, implementing a new loop type with a few more keywords wouldn't really serve a purpose, and there isn't a clear syntactical way of doing this.
You could always #define unless(p) if (!(p)) break;, or even change unless to insure if you feel like it.
>>3
Blizzard's "jass" scripting language for Warcraft 3 maps has such a construct. It might even have been attractive if it weren't the only way to control a loop and if the language weren't PIG DISGUSTING for many other reasons anyway.
That's like saying recursion is dangerous because of potential for stack overflows(tail-recursion can lead to loops, thus according to OP is dangerous too). Oh wait, the language wouldn't be touring complete if you couldn't loop. Thus all programming is dangerous.