E01071: 'continue' does not exist in EK9 - use stream pipelines with 'filter' or 'skip'
What went wrong
The 'continue' keyword does not exist in EK9.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 145 (How do I exit a loop early or skip iterations in EK9?)
- ek9 -q 148 (How do I migrate complex control flow from Java or Python...)
- ek9 -q 144 (Why doesn't EK9 have break, continue, or return statements?)
- ek9 -q 65 (How do I use a for loop to iterate over a collection?)
- ek9 -q 64 (How do I write a for loop over a range of numbers?)
Rationale
EK9 excludes 'continue' based on production bug evidence:
- Dijkstra (1968): "Go To Statement Considered Harmful" - continue is a restricted jump out of the structured flow
- In nested loops it moves on only the innermost loop, which is easy to misread
How to fix it
Replace loop + continue with stream pipelines using 'filter' (keep matching) or 'reject' (remove matching) to control which items continue along the pipeline.
See also
- E01070: 'break' not supported (use stream pipelines with 'head')
- E01071: 'continue' not supported (use stream pipelines with 'filter')
- E01072: 'return' not supported (use return declarations)
- E01073: 'null' not supported (use tri-state semantics)
- E01074: semicolons not needed (indentation-based syntax)
https://ek9.io/streamsAndPipelines.html https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="continue")]
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E01071: 'continue' does not exist in EK9 - use stream pipelines with 'filter' or 'skip'
#!ek9 defines module error.e01071.bad defines constant Unlucky <- 13 defines function printLucky() -> items as List of Integer stdout <- Stdout() for item in items if item == Unlucky continue stdout.println($item)
Fixed: Do the work only when it applies: turn the skip around
#!ek9 defines module error.e01071.good.fix defines constant Unlucky <- 13 defines function printLucky() -> items as List of Integer stdout <- Stdout() for item in items if item <> Unlucky stdout.println($item)
Fixed: Filter out the items you would have skipped with continue
#!ek9 defines module error.e01071.good defines constant Unlucky <- 13 defines function isLucky() -> item as Integer <- rtn as Boolean: item <> Unlucky luckyTotal() -> items as List of Integer <- total as Integer: 0 cat items | filter by isLucky > total printLucky() -> items as List of Integer stdout <- Stdout() for item in items if isLucky(item) stdout.println($item)
Questions and answers
These Q&A entries show E01071 and its fix:
- Q64: How do I write a for loop over a range of numbers?
- Q65: How do I use a for loop to iterate over a collection?
- Q144: Why doesn't EK9 have break, continue, or return statements?
- Q145: How do I exit a loop early or skip iterations in EK9?
- Q148: How do I migrate complex control flow from Java or Python to EK9?
- Q275: Why does AI use break and continue in EK9?
- Q1021: How do I skip items in a loop in EK9 without continue?
Found a problem?
If EK9 reported E01071 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.