by thriqon · 10y ago · 0 comments
for (pos = 0; !found; pos++) {
row = get_next_row();
if (strstr(row, "user") {
// this is obviously a header row
continue
}
if (strstr(row, user_name)) {
found = 1;
}
} for (pos = 0; !found; pos++)
This is so cool, I have never thought about this in like a decade of programming. I mean using a bool variable within a for loop. for (pos = 0; !found || pos < limit; pos++)
but there is nothing wrong in using an iterator and break out of the loop, especially if the language or the library gives you iterators.When you are over the iteration limit you want to trigger True && False which is False to break out of the loop where the right side False is the condition when pos > limit
Btw this is covered in Code Complete Second Edition by Microsoft Press on page 378-380
I'd say fair, but...
> indeed try to avoid languages where "for" allows such arbitrary constructs.
... come on. I'd say - go for such languages, they give you if a tiny bit more expressive power than ones who don't let you write such a loop.