how to skip the next (n) item & continue from (n+1) with a range ? e.g. in File(fn).byLine();
Steven Schveighoffer
schveiguy at gmail.com
Mon Jun 22 20:00:50 UTC 2020
On 6/22/20 3:53 PM, mw wrote:
> Hi,
>
> I need this logic:
>
> ```
> auto range = File(fn).byLine();
> foreach (line; range) {
> if (comeCond(line)) {
> // skip the next n line
> // and continue the foreach loop from the (n+1) line
> } else {
> regularProcess(line);
> }
> }
> ```
>
> Is it possible to do this in a foreach loop?
I wouldn't recommend it, instead do a while loop:
auto range = File(fn).byLine;
while(!range.empty)
{
auto line = range.front;
if(someCond(line)) {
range.popFrontN(n);
} else {
regularProcess(line);
range.popFront;
}
}
-Steve
More information about the Digitalmars-d-learn
mailing list