How do I skip items in a loop in EK9 without continue?

← Control Flow · Ref: Q1021

EK9 has no continue statement. Use a stream pipeline with 'filter by' to keep only the items you want, or 'reject by' to remove the items you don't want.

OTHER LANGUAGE (with continue):

  for item in items
    if not isValid(item)
      continue
    process(item)

EK9 (with filter):

  cat items | filter by isValid > stdout

EK9 (with reject — inverse of filter):

  cat items | reject by isInvalid > stdout

For loops where you need to skip based on a condition but also do work on each item:

  for item in items
    if isValid(item)
      process(item)

This is a simple if inside a for — no continue needed. The EK9 indentation makes the control flow clear.

Example

defines module qa.controlflow.replacecontinue

  defines function

    isEvenNumber() as pure
      -> number as Integer
      <- rtn as Boolean: number mod 2 == 0

  defines program

    ReplaceContinueDemo()
      stdout <- Stdout()

      numbers <- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

      //Stream approach: filter keeps only even numbers
      stdout.println("Even numbers (stream):")
      cat numbers | filter by isEvenNumber > stdout

      //Loop approach: if condition replaces continue
      stdout.println("Even numbers (loop):")
      for number in numbers
        if isEvenNumber(number)
          stdout.println($number)

Common mistakes

E01071 — 'continue' does not exist in EK9 — use 'filter by' in a stream pipeline or an 'if' condition inside the loop to skip items. See ek9 -h E01071 for details.

Incorrect:

continue

Correct:

stdout.println($number)
Other ways to ask this
  • What replaces continue in EK9?
  • How do I skip certain items when processing a collection?
  • EK9 has no continue — what do I use instead?

Coming from another language?

EK9 replaces continue with filter in stream pipelines or simple if conditions in loops. The intent is clearer without continue.

Keywords: loop, reject, replace, filter, skip, continue